home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / icu-1.3.1 / icuapps / locexp / locexp.c < prev    next >
C/C++ Source or Header  |  2000-02-23  |  101KB  |  3,517 lines

  1. /*
  2.   TODO's:
  3.  
  4.   - javascript on the explore button
  5.  
  6.   -- lots of updates
  7.     - initSortable needs to init only a part of the name. 
  8.  
  9.     - localize '>', ',' (list sep)
  10.  
  11.     - improve the 'default' pattern in the DTexplorer
  12.  
  13.   TOO MANY COMMENTS ;)
  14. */
  15.  
  16.  
  17. /*
  18. *******************************************************************************
  19. *                                                                             *
  20. * COPYRIGHT:                                                                  *
  21. *   (C) Copyright International Business Machines Corporation, 1998, 1999     *
  22. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  23. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  24. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  25. *                                                                             *
  26. *******************************************************************************
  27. *
  28. * File listrb.c
  29. *
  30. * Modification History:
  31. *
  32. *   Date        Name        Description
  33. *   7/14/1999    srl        Created
  34. *   8/16/1999    srl        Display overhaul - locale status at bottom, etc.
  35. *  10/14/1999    srl        Update for ICU1.3+, prepare for checkin!!
  36. *******************************************************************************
  37. */
  38.  
  39.  
  40. /* ==Note==
  41.  
  42.    this is a very UI intensive application. 
  43.    It uses a whole pile of globals to maintain state and pass data 
  44.    back and forth. As a result, it has a lot of 'convenience functions'
  45.    that make sense in very limited contexts.
  46.  
  47.    If this thing was pulled into a multithreaded environment 
  48.    they could probably be put in a paramblock of some sort. I was mostly
  49.    just trying to keep the arg count and complexity down. For example, 
  50.    OUT the ubiquitous output file.
  51.  
  52.                          -- Steven R. Loomis
  53.  
  54. */
  55.    
  56.  
  57. #include "stdio.h"
  58. #include "stddef.h"
  59. #include "string.h"
  60. #include "ustdio.h"
  61. #include "ucnv.h"
  62. #include "ustring.h"
  63. #include "udat.h"
  64. #include "uloc.h"
  65. #include "ures.h"
  66. #include "ucol.h"
  67. #include "ucal.h"
  68. #include "ctype.h"
  69. #include "lx_utils.h"
  70. #include "ures_additions.h"
  71. #include "decompcb.h"
  72.  
  73. /********************** Some Konstants **** and structs ***************/
  74.  
  75. #ifndef URLPREFIX
  76. # define kStaticURLPrefix "/developerworks/opensource/icu/project"
  77. #else
  78. # define kStaticURLPrefix  URLPREFIX
  79. #endif
  80.  
  81. /* #define kStaticURLPrefix ""  */
  82.  
  83.  
  84. /* Define the following to enable 'demonstrate collation' */
  85. #define kUSort "/home/srl/icu/source/samples/usort/usort"
  86.  
  87. #define kStatusBG "\"#EEEEEE\" " 
  88.  
  89.  
  90. #define kShowStringCutoffSize 200
  91. #define kShow2dArrayRowCutoff 5
  92. #define kShow2dArrayColCutoff 5
  93.  
  94.  
  95. /********************* prototypes ***************************/
  96.  
  97. int main(const char *argv[], int argc);
  98.  
  99. /* setup the UFILE */
  100. UFILE *setLocaleAndEncodingAndOpenUFILE();
  101.  
  102. /* Setup the 'locales' structure */
  103. void   setupLocaleTree();
  104.  
  105. /* some fcns for different parts of the screen */
  106. void doFatal(const char *what, UErrorCode err);
  107. void printStatusTable();
  108.  
  109. /**
  110.  * Print the path [ ICU LocaleExplorer > default > English > English (Canadian) ...] 
  111.  * @param leaf Which node to start printing at
  112.  * @param current The locale that should be selected
  113.  * @param styled Should bold tags and links be put in?
  114.  */
  115. void printPath(const MySortable *leaf, const MySortable *current, bool_t styled);
  116.  
  117. /* selection of locales and converter */
  118. void chooseLocale(bool_t toOpen, const char *current, const char *restored);
  119. void chooseConverter(const char *restored);
  120. void listBundles(char *b);
  121.  
  122. /* fcns for dumping the contents of a particular rb */
  123. void showFlagImage(const char *locale, const char *extraIMGparams);
  124. void showCollationElements(UResourceBundle *rb, const char *locale, const char *qs, const char *whichString);
  125. void showString(UResourceBundle *rb, const char *locale, const char *qs, const char *whichString);
  126. void showLocaleCodes(UResourceBundle *myRB, const char *locale);
  127. void showStringWithDescription(UResourceBundle *rb, const char *locale, const char *qs, const UChar *desc[], const char *whichString, bool_t hidable);
  128. void showArray(UResourceBundle *rb, const char *locale, const char *whichString);
  129. void showArrayWithDescription(UResourceBundle *rb, const char *locale, const UChar *desc[], const char *whichString);
  130. void show2dArrayWithDescription(UResourceBundle *rb, const char *locale, const UChar *desc[], const char *queryString, const char *whichString);
  131. void showTaggedArray(UResourceBundle *rb, const char *locale, const char *queryString, const char *whichString);
  132. void showShortLong(UResourceBundle *rb, const char *locale, const char *keyStem, const UChar *shortName, const UChar *longName, int32_t num);
  133. void showDateTimeElements(UResourceBundle *rb, const char *locale);
  134. void explainStatus(UErrorCode status, const char *tag); /* utility fcn to explain an errorcode. [tag = #tag ] */
  135. void showSort(const char *locale, const char *b);
  136.  
  137. void showExploreDateTimePatterns(UResourceBundle *rb, const char *locale, const char *b);
  138. void showExploreNumberPatterns  (const char *locale, const char *b);
  139.  
  140. void showExploreButton(UResourceBundle *rb, const char *locale, const UChar *sampleString, const char *key);
  141. void showExploreCloseButton(const char *locale, const char *frag);
  142.  
  143. bool_t didUserAskForKey(const char *key, const char *queryString);
  144.  
  145. /*  Pluggable UI.  Put these before and after each item. */
  146. void showKeyAndStartItem(const char *key, const UChar *keyName, const char *locale, UErrorCode showStatus);
  147. void showKeyAndStartItemShort(const char *key, const UChar *keyName, const char *locale, UErrorCode showStatus);
  148. void showKeyAndEndItem(const char *key, const char *locale);
  149.  
  150.  
  151. /* fetch string with fallback */
  152. const UChar *FSWF(const char *key, const char *fallback);
  153.  
  154. /* write a string in \uXXXX format */
  155. void writeEscaped(const UChar *s);
  156.  
  157. /* is this a locale we should advertise as supported? */
  158. bool_t isSupportedLocale(const char *locale, bool_t includeChildren);
  159.  
  160.  
  161. void printHelpTag(const char *helpTag, const UChar *str);
  162. /* ex: printHelpImg("coffee", L"[coffee help symbol]", L"coffee-help.gif", L"BORDER=3"); */
  163. void printHelpImg(const char *helpTag, const UChar *alt, const UChar *img, const UChar *options);
  164.  
  165. void exploreFetchNextPattern(UChar *dstPattern, const char* qs);
  166. void exploreShowPatternForm(UChar *dstPattern, const char *locale, const char *key, const char* qs, double value, UNumberFormat *valueFmt);
  167.  
  168. /********************** globals ********************/
  169. UFILE *OUT = NULL;                     /* used everywhere */
  170. const char *couldNotOpenEncoding;      /* contains error string if nonnull */
  171. const char *ourCharsetName = "iso-8859-1"; /* HTML friendly name of the current charset */
  172.  
  173. bool_t setEncoding = FALSE;            /* what is our state? What's setup? */
  174. bool_t setLocale = FALSE;
  175.  
  176. UResourceBundle *gRB  = 0;             /* the RB to get our localized strs from (for this app) */
  177. UResourceBundle *defaultRB = 0;        /* RB in the selected locale */
  178.  
  179. UErrorCode rbErr = U_ZERO_ERROR;         /* errorcode if above is null */
  180.  
  181. /* ====== locale navigation ===== */
  182. MySortable      *locales   = NULL;     /* tree of locales */
  183. MySortable      *curLocale = NULL;     /* Current locale */
  184. char             curLocaleName[128];
  185. MySortable      *parLocale = NULL;     /* Parent locale of current */
  186.  
  187. int32_t          numLocales = 0;
  188. /************************ fcns *************************/
  189.  
  190. /*UChar x[2] = { 0x0030, 0x0000 };*/ /* test string */
  191.  
  192. const char *myBundlePath()
  193. {
  194.   static char gMyBundlePath[500] = "";
  195.  
  196.   if(gMyBundlePath[0] == 0)
  197.     {
  198.       strcpy(gMyBundlePath, icu_getDefaultDataDirectory());
  199.       strcat(gMyBundlePath, "locexp/");
  200.     }
  201.   
  202.   return gMyBundlePath;
  203. }
  204.  
  205. /*** fetch string with fallback -------------------------------------------------*/
  206. const UChar *FSWF(const char *key, const char *fallback)
  207. {
  208.   UErrorCode status = U_ZERO_ERROR;
  209.   const UChar *str = 0;
  210.   static UChar   gFSWFTempChars[1024];
  211.  
  212.   if(strlen(fallback) >  1020)
  213.     ((char*)fallback)[1020] = 0; /* const violation. Tough. */
  214.  
  215.   if(gRB == 0)
  216.     {
  217.       gRB = ures_open(  myBundlePath(), NULL, &status);
  218.       if(U_FAILURE(status))
  219.     {
  220.       gRB = 0;
  221.       rbErr = status;
  222.     }
  223.     }
  224.  
  225.   status = U_ZERO_ERROR;
  226.  
  227.   if(gRB != 0)
  228.     str = ures_get( gRB, key, &status);
  229.  
  230.   if(str == 0) /* failed to get a str */
  231.     {
  232.       /* fallback: use our temp buffer [NON MT safe] and do a strcpy.. */
  233.       u_uastrcpy(gFSWFTempChars, fallback);
  234.       str = malloc((u_strlen(gFSWFTempChars)+1) * sizeof(UChar)); /* LEAK but who cares, it's an error case */
  235.       u_strcpy((UChar*)str,gFSWFTempChars);
  236.     }
  237.  
  238.   return str;
  239. }
  240.  
  241. /* main function. we write the outside html page here as well. ----------------------------*/
  242.  
  243. int main(const char *argv[], int argc)
  244. {
  245.   UErrorCode status;
  246.   char *tmp;
  247.   UChar subTitle[1024];
  248.   int32_t n;
  249.  
  250.   /*  fprintf(stderr, "PID=%d\n", getpid()); */
  251.   /*   system("sleep 20");  */
  252.   
  253.   status = U_ZERO_ERROR;
  254.  
  255.   ourCharsetName = MIMECharsetName(ucnv_getDefaultName()); /* for some sanity */
  256.  
  257.   OUT = setLocaleAndEncodingAndOpenUFILE();
  258.   if(!OUT)
  259.     doFatal("u_finit trying to open file", 0);
  260.   
  261.   setupLocaleTree();
  262.  
  263.   printf("content-type: text/html;charset=%s\r\n\r\n\r\n\n", ourCharsetName);
  264.   fflush(stdout);
  265.  
  266.   /* 
  267.      kore wa nandesuka?
  268.      xi trid?
  269.  
  270.      
  271.      {
  272.     char langBuf[100];
  273.     uloc_getLanguage(NULL,langBuf,100,&status);
  274.   printf("Content-Language: %s\r\n", langBuf);
  275.   }*/
  276.  
  277.   printf("\n" );
  278.  
  279.  
  280.   fflush(stdout); /* and that, as they say, is that.  All UFILE from here.. */
  281.  
  282.   u_fprintf(OUT,"<HTML>");
  283.  
  284.   u_fprintf(OUT, "\r\n<!-- \r\n\r\n   Hello, HTML explorer :)  Don't know how readable this HTML will be!\r\n  If you have any questions, comments, [gasp] bugs, or\r\n [hopehope] improvements, please drop some knowledge to:\r\n    icu4c@us.ibm.com THX! \r\n                 ~srl \r\n\r\n-->");
  285.  
  286.   u_fprintf(OUT, "<HEAD BGCOLOR=\"#DFDDDD\"><TITLE>");
  287.  
  288.   printPath(curLocale, curLocale, FALSE);
  289.   if(strstr(getenv("QUERY_STRING"), "EXPLORE"))
  290.     u_fprintf(OUT, " > %U", FSWF("exploreTitle", "Explore"));
  291.  
  292.   u_fprintf(OUT, "</TITLE>\r\n");
  293.   
  294.   if(!getenv("PATH_INFO") || !getenv("PATH_INFO")[0])
  295.     u_fprintf(OUT, "<BASE HREF=\"http://%s%s/\">\r\n", getenv("SERVER_NAME"), getenv("SCRIPT_NAME")); /* Ensure that all relative paths have the cgi name followed by a slash. */
  296.   
  297.   
  298.   u_fprintf(OUT, "%U", 
  299.         FSWF ( /* NOEXTRACT */ "htmlHEAD",
  300.            "</HEAD>\r\n<BODY BGCOLOR=\"#FFFFFF\" > \r\n")
  301.         );
  302.   /* now see what we're gonna do */
  303.   tmp = getenv ( "QUERY_STRING" );
  304.   
  305.   if(strstr(tmp,"EXPLORE"))
  306.     {
  307.       printHelpImg("display", 
  308.            FSWF("display_ALT", "Display Problem?"),
  309.            FSWF("display_GIF", "displayproblems.gif"),
  310.            FSWF("display_OPTIONS", "ALIGN=RIGHT"));
  311.           
  312.       u_fprintf(OUT, "<FONT SIZE=+1>");
  313.       printPath(curLocale, curLocale, FALSE);
  314.       u_fprintf(OUT, "</FONT><P>");
  315.  
  316.  
  317.     }
  318.   else
  319.     {
  320.       if(tmp && tmp[0]  && !curLocale && (tmp[0] == '_'))
  321.     {
  322.       UChar dispName[1024];
  323.       UErrorCode stat = U_ZERO_ERROR;
  324.       dispName[0] = 0;
  325.       uloc_getDisplayName(curLocaleName, NULL, dispName, 1024, &stat);
  326.       
  327.       u_fprintf(OUT, "<UL><B>%U  [%U]</B></UL>\r\n",
  328.             FSWF("warningInheritedLocale", "Note: You're viewing a non existent locale. The ICU will support this with inherited information. But the Locale Explorer is not designed to understand such locales. Inheritance information may be wrong!"), dispName);
  329.     }
  330.  
  331.  
  332.       u_fprintf(OUT, "<TABLE WIDTH=100%%><TR><TD ALIGN=LEFT VALIGN=TOP>");
  333.  
  334.       u_fprintf(OUT, "<FONT SIZE=+1>");
  335.       printPath(curLocale, curLocale, TRUE);
  336.       u_fprintf(OUT, "</FONT><P>");
  337.       
  338.       u_fprintf(OUT, "</TD><TD ROWSPAN=2 ALIGN=RIGHT VALIGN=TOP WIDTH=1>");
  339.       
  340.       printHelpImg("display", 
  341.            FSWF("display_ALT", "Display Problem?"),
  342.            FSWF("display_GIF", "displayproblems.gif"),
  343.            FSWF("display_OPTIONS", "ALIGN=RIGHT"));
  344.           
  345.       u_fprintf(OUT, "\r\n</TD></TR><TR><TD>");
  346.  
  347.       if(curLocale && curLocale->nSubLocs)
  348.     {
  349.       u_fprintf(OUT, "%U<BR><UL>", FSWF("sublocales", "Sublocales:"));
  350.  
  351.       mySort(curLocale, &status, FALSE); /* Sort sub locales */
  352.  
  353.       for(n=0;n<curLocale->nSubLocs;n++)
  354.         {
  355.           if(n != 0)
  356.         u_fprintf(OUT, ", ");
  357.           u_fprintf(OUT, "<A HREF=\"?_=%s\">%U</A>",
  358.             curLocale->subLocs[n].str,
  359.             curLocale->subLocs[n].ustr);
  360.         }
  361.       u_fprintf(OUT, "</UL>");
  362.     }
  363.       u_fprintf(OUT, "</TD></TR></TABLE>\r\n");
  364.  
  365.  
  366.     }
  367.  
  368.  
  369.   if ( tmp == NULL )
  370.     tmp = ""; /* for sanity */
  371.  
  372.   if( ((!*tmp) && !setLocale && !setEncoding) || strstr(tmp, "PANICDEFAULT")) /* They're coming in cold. Give them the spiel.. */
  373.   {
  374.     u_fprintf(OUT, "</H2>"); /* close the 'title text */
  375.  
  376.     u_fprintf(OUT, "<UL>%U<P>\r\n",
  377.       FSWF("introSpiel", "This demo illustrates the IBM International Classes for Unicode localization data.  The classes cover 45 different languages, further divided into 154 geographic locales.  For each language, data such as days of the week, months, and their abbreviations are defined.  <P> The IBM Classes for Unicode are open-source. See the <A HREF=../project>ICU Project Page</A>  for further information."));
  378.  
  379.     u_fprintf(OUT, "</UL>");
  380.   }
  381.  
  382.   /* Logic here: */
  383.   if( /* !setLocale || */  !strncmp(tmp,"locale", 6))     /* ?locale  or not set: pick locale */
  384.     {
  385.       char *restored;
  386.  
  387.       restored = strchr(tmp, '&');
  388.       if(restored)
  389.     {
  390.       restored ++;
  391.     }
  392.  
  393.       if(!restored)
  394.     restored = "converter"; /* what to go on to */
  395.  
  396.       if(setLocale)
  397.     u_fprintf(OUT, ": %U</H2>\r\n", FSWF("changeLocale", ": Change Your Locale"));
  398.       else
  399.     u_fprintf(OUT, ": %U</H2>\r\n", FSWF("chooseLocale", ": Choose Your Locale."));
  400.  
  401.  
  402.       u_fprintf(OUT, "<TABLE WIDTH=\"70%\"><TR>");
  403.       
  404.  
  405.       u_fprintf(OUT, "<TD COLSPAN=2 ALIGN=RIGHT>");
  406.  
  407.       printHelpTag("chooseLocale", NULL);
  408.  
  409.       u_fprintf(OUT, "</TD></TR></TABLE>\r\n");
  410.  
  411.       chooseLocale(FALSE, (char*)uloc_getDefault(), restored);
  412.     }
  413.   else if (!strncmp(tmp,"converter", 9))  /* ?converter */
  414.     {
  415.       char *restored;
  416.  
  417.       restored = strchr(tmp, '&');
  418.       if(restored)
  419.       restored ++;
  420.  
  421.       /*
  422.       if(setEncoding)
  423.     u_fprintf(OUT, ": %U</H2>\r\n", FSWF("changeEncoding", "Change Your Encoding"));
  424.       else
  425.     u_fprintf(OUT, ": %U</H2>\r\n", FSWF("chooseEncoding", "Choose Your Encoding"));
  426.       */
  427.       u_fprintf(OUT, "<HR>");
  428.       chooseConverter(restored);
  429.     }
  430.   else
  431.     {
  432.       listBundles(tmp);
  433.     }
  434.   
  435.   u_fprintf(OUT, "<P><BR><P><P><BR><A NAME=\"mySettings\"></A><P><P><P><P><HR>");
  436.   printStatusTable();
  437.   u_fprintf(OUT, "<I>%U</I> 1.3.1+<BR>", FSWF("poweredby", "Powered by ICU"));
  438.   u_fprintf(OUT, "%U", date(NULL,UDAT_FULL,&status));
  439.   
  440.   if(!gRB)
  441.     {
  442.       /* No reason to use FSWF, this error means we have nothing to fetch strings from! */
  443.       u_fprintf(OUT, "<HR><B><I>Note: Could not open our private resource bundle %s, err %d </I></B><P>\r\n",
  444.         myBundlePath(), rbErr);
  445.     }
  446.  
  447.   
  448.   u_fprintf(OUT, "%U", FSWF( /* NOEXTRACT */ "htmlTAIL", "<!-- No HTML footer -->"));
  449.     
  450.   /* a last resort. will switch to English if they get lost.. */
  451.   /* DO NOT localize the following */
  452.   /* What this does:  
  453.          - brings them to the 'choose your locale' pane in English, then
  454.      - brings them to the 'choose your encoding' pane in their locale, then
  455.      - lists the locales to browse
  456.   */
  457.  
  458. #ifndef NO_LOCALE_CHANGE
  459.   u_fprintf(OUT, "<A HREF=\"%s/en/iso-8859-1/?PANICDEFAULT\"><IMG SRC=\"%s/localeexplorer/incorrect.gif\" ALT=\"Click here if text displays incorrectly\"></A>", getenv("SCRIPT_NAME"), kStaticURLPrefix);
  460. #endif
  461.  
  462.   if(!strcmp(uloc_getDefault(),"klingon"))
  463.     u_fprintf(OUT, "<P>Thank you for using the ICU LocaleExplorer, from %s compiled %s %s<P>\r\n", LXHOSTNAME, __DATE__, __TIME__);
  464.  
  465.   u_fprintf(OUT, "</BODY></HTML>\r\n");
  466.  
  467.   u_fclose(OUT);
  468.  
  469.   if(gRB)
  470.     ures_close(gRB);
  471.  
  472.   if(defaultRB)
  473.     ures_close(defaultRB);
  474.  
  475. }
  476.  
  477. const UChar *defaultLanguageDisplayName()
  478. {
  479.   UErrorCode status = U_ZERO_ERROR;
  480.   static UChar displayName[1024] = { 0x0000 };
  481.  
  482.   if(displayName[0] == 0x0000)
  483.     {
  484.       uloc_getDisplayLanguage(uloc_getDefault(), uloc_getDefault() ,displayName, 1024, &status);
  485.     }
  486.   
  487.   return displayName;
  488. }
  489.  
  490. /* snag the locale, followed optionally by the encoding, from the path_info -----------------
  491. This is the only fcn which should be calling ucnv_setDefaultName
  492. */
  493.  
  494. #ifdef HACKY_DEV_TIEIN
  495.   extern int srl_mode;
  496. #endif
  497.  
  498. UFILE *setLocaleAndEncodingAndOpenUFILE()
  499. {
  500.   char *pi;
  501.   char *tmp;
  502.   const char *locale = NULL;
  503.   const char *encoding = NULL;
  504.   UErrorCode status = U_ZERO_ERROR;
  505.   char *acceptLanguage;
  506.   char newLocale[100];
  507.   UFILE *f;
  508.  
  509.   uloc_setDefault("en", &status); /* BASELINE */
  510.  
  511.   locale = (const char *)uloc_getDefault();
  512.   encoding = ucnv_getDefaultName(); 
  513.  
  514.   pi = getenv("PATH_INFO");
  515.   if( (pi) && (*pi && '/') )
  516.     {
  517.       pi++; /* eat first slash */
  518.       tmp = strchr(pi, '/');
  519.       
  520.       if(tmp)
  521.     *tmp = 0; /* tie off at the slash */
  522.  
  523.       status = U_ZERO_ERROR;
  524.       locale = pi;
  525.  
  526.       if ( *locale != 0) /* don't want 0-length locales */
  527.     {
  528.       uloc_setDefault(locale, &status);
  529.       if(U_FAILURE(status))
  530.         {
  531.           doFatal("uloc_setDefault", status);
  532.           /* doesn't return */
  533.         }
  534.       setLocale = TRUE;
  535.     }
  536.  
  537.       if(tmp) /* have encoding */
  538.     {
  539.   
  540.       tmp++; /* skip '/' */
  541.   
  542.       pi = tmp;
  543.  
  544.       tmp = strchr(tmp, '/');
  545.       if(tmp)
  546.         *tmp = 0;
  547.   
  548.       if(*pi) /* don't want 0 length encodings */
  549.         {
  550.           encoding = pi;
  551.           setEncoding = TRUE; 
  552.  
  553.  
  554.  
  555.           ourCharsetName = MIMECharsetName(encoding);
  556.         }
  557.     }
  558.     }
  559.  
  560.   if(!setLocale && (acceptLanguage=getenv("HTTP_ACCEPT_LANGUAGE")) && acceptLanguage[0] )
  561.     {
  562.  
  563.       /* OK, if they haven't set a locale, maybe their web browser has. */
  564.     if(!(tmp=strchr(acceptLanguage,','))) /* multiple item separator */
  565.       if(!(tmp=strchr(acceptLanguage,'='))) /* strength separator */
  566.       tmp = acceptLanguage + strlen(acceptLanguage);
  567.  
  568.       strncpy(newLocale, acceptLanguage, my_min(100,tmp-acceptLanguage));
  569.       newLocale[my_min(100,tmp-acceptLanguage)] = 0;
  570.       /*      fprintf(stderr," NL=[%s], al=[%s]\r\n", newLocale, acceptLanguage);
  571.           fflush(stderr);*/
  572.  
  573.       /* Note we don't do the PROPER thing here, which is to sort the possible languages by weight. Oh well. */
  574.       
  575.       status = U_ZERO_ERROR;
  576.  
  577.       /* half hearted attempt at canonicalizing the locale string. */
  578.       newLocale[0] = tolower(newLocale[0]);
  579.       newLocale[1] = tolower(newLocale[1]);
  580.       if(newLocale[2] == '-')
  581.     newLocale[2] = '_';
  582.       if(newLocale[5] == '-')
  583.     newLocale[5] = '_';
  584.  
  585.       newLocale[3] = toupper(newLocale[3]);
  586.       newLocale[4] = toupper(newLocale[4]);
  587.  
  588.       if(isSupportedLocale(newLocale, TRUE)) /* DO NOT pick an unsupported locale from the browser's settings! */
  589.     uloc_setDefault(newLocale, &status);
  590.       status = U_ZERO_ERROR;
  591.  
  592.       /* that might at least get something.. It's better than defaulting to en_US */
  593.     }
  594.   
  595.   if(!setEncoding)
  596.     {
  597.       const char *accept;
  598.       const char *agent;
  599.             char *newEncoding;
  600.  
  601.       accept = getenv("HTTP_ACCEPT_CHARSET");
  602.  
  603.  
  604.       if(accept && strstr(accept, "utf-8"))
  605.     {
  606.       encoding = "utf-8"; /* use UTF8 if they have it ! */
  607.     }
  608.       else if( (agent = (const char *)getenv("HTTP_USER_AGENT")) &&
  609.        (strstr(agent, "MSIE 4") || strstr(agent, "MSIE 5")) &&
  610.        (strstr(agent, "Windows NT")))
  611.     {
  612.       encoding = "utf-8"; /* MSIE can handle utf8 but doesn't request it. */
  613.     }
  614.       else /* OK, see if we can find a valid codepage */
  615.     {
  616.       const UChar *defaultCodepage;
  617.       int32_t i = 0;
  618.       UErrorCode status;
  619.  
  620.       FSWF( /*NOEXTRACT*/ "",""); /* just to init it.. */
  621.       if(gRB)
  622.         {
  623.           while( (defaultCodepage = ures_getArrayItem(gRB, "DefaultEncoding", i++, &status)) &&
  624.              U_SUCCESS(status) )
  625.         {
  626.           newEncoding = malloc(u_strlen(defaultCodepage) + 1);
  627.           u_austrcpy((char*)newEncoding, defaultCodepage);
  628.  
  629.           if(accept)
  630.             {
  631.               fprintf(stderr,"Looking for %s in %s..\n", newEncoding, accept);
  632.               if(strstr(accept,newEncoding) || strchr(accept,'*'))
  633.             encoding = newEncoding;
  634.               break;
  635.             }
  636.           else
  637.             free(newEncoding);
  638.         }
  639.  
  640.           fprintf(stderr,"Got %d on try %d for defaultencoding [bnd%s]\n", status, i-1, uloc_getDefault() );
  641.         }
  642.       else
  643.         {
  644.           /* default wasn't accepted. */
  645.         }
  646.  
  647.     }
  648.  
  649.     }
  650.  
  651.   if(encoding)
  652.     {
  653.       ourCharsetName = MIMECharsetName(encoding);
  654.  
  655. #ifdef HACKY_DEV_TIEIN
  656.  
  657.       if(!strcmp(encoding, "x-devanagari"))
  658.     {
  659.       ourCharsetName = encoding;
  660.       srl_mode = 3; /* turn on dev processing */
  661.       encoding = "iso-8859-1";
  662.     }
  663. #endif
  664.  
  665.       ucnv_setDefaultName(encoding);
  666.     }
  667.  
  668.   /* Open an RB in the default locale */
  669.   defaultRB = ures_open(NULL, NULL, &status);
  670.  
  671.   /* now, open the file */
  672.   f = u_finit(stdout, locale, encoding);
  673.  
  674.   if(!f)
  675.     {
  676.       couldNotOpenEncoding = encoding;
  677.       f = u_finit(stdout, locale, "LATIN_1"); /* this fallback should only happen if the encoding itself is bad */
  678.       if(!f)
  679.     return f; /* :( */
  680.     }
  681.  
  682.  
  683.   /* we know that ufile won't muck withthe locale.
  684.      But we are curious what encoding it chose, and we will propagate it. */
  685.   if(encoding == NULL)
  686.     {
  687.       encoding = u_fgetcodepage(f);
  688.       ucnv_setDefaultName(encoding);
  689.     }
  690.  
  691.   /* put our special error handler in */
  692.   /*  ucnv_setFromUCallBack((UConverter*)u_fgetConverter(f), &UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE_HTML, &status); */
  693.  
  694.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(f), &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);
  695.  
  696.   /* Change what DECOMPOSE calls as it's last resort */
  697.   DECOMPOSE_lastResortCallback = UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE_HTML;
  698.  
  699.   return f;
  700. }
  701.  
  702. void setupLocaleTree()
  703. {
  704.   const char *qs, *amp;
  705.   char       *loc = curLocaleName;
  706.  
  707.   /* setup base locale */
  708.   locales = createLocaleTree(NULL, &numLocales);
  709.  
  710.   qs = getenv("QUERY_STRING");
  711.   if(   qs &&
  712.      (*(qs++) == '_') &&
  713.      (*(qs++) == '='))
  714.     {
  715.       amp = strchr(qs,'&');
  716.       if(!amp)
  717.     amp = qs+strlen(qs);
  718.       
  719.       if((amp-qs)>100) /* safety */
  720.     {
  721.       strncpy(loc,qs,100);
  722.       loc[100] = 0;
  723.     }
  724.       else
  725.     {
  726.       strncpy(loc,qs,amp-qs);
  727.       loc[amp-qs] = 0;
  728.     }
  729.       
  730.       /* setup cursors.. */
  731.       curLocale = findLocale(locales, loc);
  732.  
  733.       if(curLocale)
  734.     parLocale = curLocale->parent;
  735.     }
  736. }
  737.   
  738. /* do a fatal error. may not have a content type yet. --------------------------------------- */
  739. /* TODO: this doesn't actually work yet. Should it be localized ? probably. */
  740. void doFatal(const char *what, UErrorCode err)
  741. {
  742.   fprintf(stdout, "Content-type:text/html\r\n\r\n");
  743.   fprintf(stdout, "<TITLE>ICU LocaleExplorer: Error</TITLE>\r\n");
  744.   fprintf(stdout, "<H1>ICU LocaleExplorer: Error</H1>\r\n");
  745.   fprintf(stdout, "<UL>An error of type %d occured while trying to %s.</UL><HR><P>\r\n",err,what);
  746.   fprintf(stderr, "listrb: err %d trying to %s\n",err,what);
  747.   fprintf(stdout, "You can try <A HREF=\"%s\">starting over</A>, or complain to srl.<P>\r\n",
  748.      getenv("SCRIPT_NAME"));
  749.   fflush(stdout);
  750.   exit(0);
  751. }
  752.  
  753. void writeEscaped(const UChar *s)
  754. {
  755.   UErrorCode status = U_ZERO_ERROR;
  756.  
  757.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE, &status); 
  758.  
  759.   if(u_strchr(s, 0x00A0))
  760.     {
  761.       while(*s)
  762.     {
  763.       if(*s == 0x00A0)
  764.         u_fprintf(OUT, " ");
  765.       else
  766.         u_fprintf(OUT, "%K", *s);
  767.       
  768.       s++;
  769.     }
  770.     }
  771.   else
  772.     u_fprintf(OUT, "%U", s); 
  773.   
  774.   /* should 'get/restore' here. */
  775.   /*  ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &SubstituteWithValueHTML, &status); */
  776.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);
  777. }
  778.  
  779. void writeEscapedQuery(const UChar *s)
  780. {
  781.   UErrorCode status = U_ZERO_ERROR;
  782.  
  783.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE, &status); 
  784.  
  785.   if(u_strchr(s, 0x00A0))
  786.     {
  787.       while(*s)
  788.     {
  789.       if(*s == 0x00A0)
  790.         u_fprintf(OUT, " ");
  791.       else
  792.         u_fprintf(OUT, "%K", *s);
  793.       
  794.       s++;
  795.     }
  796.     }
  797.   else
  798.     u_fprintf(OUT, "%U", s); 
  799.   
  800.   /* should 'get/restore' here. */
  801.   /*  ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &SubstituteWithValueHTML, &status); */
  802.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);
  803. }
  804.  
  805.  
  806. /* print that little box in the TR corner ----------------------------------------------------- */
  807.  
  808. void printStatusTable()
  809. {
  810.   UChar myChars[1024];
  811.   UErrorCode status;
  812.  
  813.   status = U_ZERO_ERROR;
  814.  
  815.   u_fprintf(OUT, "<TABLE BORDER=0 BGCOLOR=\"#DDDDDD\" ALIGN=RIGHT><TR>"); 
  816.   u_fprintf(OUT, "<TD ROWSPAN=2>");
  817.  
  818.   u_fprintf(OUT, "%U",
  819.        FSWF("statusTableHeader", "Your settings:<BR>(click to change)"));
  820.   u_fprintf(OUT, "</TD>");
  821.   
  822. #ifndef NO_LOCALE_CHANGE
  823.   u_fprintf(OUT, "<TD ALIGN=RIGHT><B>");
  824.  
  825.   u_fprintf(OUT, "%U</B></TD><TD>", FSWF("myLocale", "Locale:"));
  826.  
  827.   u_fprintf(OUT, "<A HREF=\"?locale");
  828.   if(strncmp(getenv("QUERY_STRING"), "locale",6))
  829.     u_fprintf(OUT,"&%s", getenv("QUERY_STRING"));
  830.   u_fprintf(OUT, "\">");
  831.  
  832.   uloc_getDisplayName(NULL, NULL, myChars, 1024, &status);
  833.   u_fprintf(OUT, "%U", myChars);
  834.  
  835.   u_fprintf(OUT, "</A>\r\n");
  836.  
  837.   
  838.   u_fprintf(OUT, "</TD>");
  839. #else
  840.   if(!isSupportedLocale(uloc_getDefault(), TRUE))
  841.     {
  842.       u_fprintf(OUT, "<TD COLSPAN=2 ALIGN=RIGHT><FONT COLOR=\"#FF0000\">");
  843.       u_fprintf_u(OUT, FSWF("locale_unsupported", "This display locale, <U>%s</U>, is unsupported."), uloc_getDefault());
  844.       u_fprintf(OUT, "</FONT></TD>");
  845.     }
  846. #endif
  847.  
  848.  
  849.  
  850.   u_fprintf(OUT, "</TR>");
  851.  
  852.   /**  Converter **/  
  853.   u_fprintf(OUT, "<TR><TD ALIGN=RIGHT><B>");
  854.  
  855.   u_fprintf(OUT, "%U</B></TD><TD>", FSWF("myConverter", "Encoding:"));
  856.   
  857.   u_fprintf(OUT, "<A HREF=\"?converter");
  858.   if(strncmp(getenv("QUERY_STRING"), "converter",9))
  859.     u_fprintf(OUT,"&%s", getenv("QUERY_STRING"));
  860.   u_fprintf(OUT, "\">");
  861.  
  862.   u_fprintf(OUT, "<FONT SIZE=+1>%s</FONT>", ourCharsetName);
  863.   u_fprintf(OUT, "</A>\r\n");
  864.   
  865.   u_fprintf(OUT, "</TD></TR>");
  866. #if 0
  867.   if(couldNotOpenEncoding)
  868.   {
  869.     /* Localize this when it actually works! */
  870.     u_fprintf(OUT,"<TR><TD COLSPAN=2><FONT COLOR=\"#FF0000\">Warning, couldn't open the encoding '%s', using a default.</FONT></TD></TR>\r\n", couldNotOpenEncoding); 
  871.   }
  872. #endif
  873.   u_fprintf(OUT, "</TABLE>\r\n");
  874. }
  875.  
  876. void printPath(const MySortable *leaf, const MySortable *current, bool_t styled)
  877. {
  878.  
  879.   if(!leaf) /* top level */
  880.     {
  881.       if(styled) 
  882.     u_fprintf(OUT, "<A HREF=\"?\">"); /* Reset */
  883.       
  884.       u_fprintf(OUT, "%U",
  885.         FSWF("title", "ICU LocaleExplorer"));
  886.       
  887.       if(styled) 
  888.     u_fprintf(OUT, "</A>");
  889.  
  890.       return;
  891.     }
  892.  
  893.   
  894.   /* reverse order recursively */
  895.   printPath(leaf->parent,current,styled);
  896.  
  897.  
  898.   u_fprintf(OUT, " > ");
  899.   
  900.  
  901.  
  902.   if(styled)
  903.     {
  904.       if(leaf == current)
  905.     u_fprintf(OUT, "<B>");
  906.  
  907.       u_fprintf(OUT, "<A HREF=\"?_=%s\">", leaf->str);
  908.     }
  909.  
  910.   
  911.   
  912.   u_fprintf(OUT, "%U", leaf->ustr);
  913.  
  914.  
  915.  
  916.   if(styled)
  917.     {
  918.       u_fprintf(OUT, "</A>");
  919.  
  920.       if(leaf == current)
  921.     u_fprintf(OUT, "</B>");
  922.  
  923.     }
  924. }
  925.  
  926.  
  927. static void printLocaleLink(bool_t toOpen, MySortable *l, const char *current, const char *restored)
  928. {
  929.   u_fprintf(OUT, "<A HREF=\"");
  930.   
  931.   if(toOpen == TRUE)
  932.     {
  933.       u_fprintf(OUT, "%s/%s/",
  934.         getenv("SCRIPT_NAME"),
  935.         (char*)uloc_getDefault());
  936.       if(setEncoding)
  937.     u_fprintf(OUT,"%s/", ucnv_getDefaultName());      
  938.       u_fprintf(OUT,"?_=%s&", l->str);
  939.     }
  940.   else
  941.     {
  942.       u_fprintf(OUT, "%s/%s/",
  943.         getenv("SCRIPT_NAME"),
  944.         l->str);
  945.       if(setEncoding)
  946.     u_fprintf(OUT,"%s/", ucnv_getDefaultName());
  947.       
  948.       if(restored)
  949.     u_fprintf(OUT, "?%s", restored);
  950.     }
  951.   
  952.   
  953.   u_fprintf(OUT,"\">");
  954.   u_fprintf(OUT, " %U", l->ustr);
  955.   
  956.   u_fprintf(OUT,"</A>");
  957.   
  958. }
  959.  
  960. static void printLocaleAndSubs(bool_t toOpen, MySortable *l, const char *current, const char *restored)
  961. {
  962.   int32_t n;
  963.  
  964.   printLocaleLink(toOpen,l,current,restored);
  965.   
  966.   if(l->nSubLocs)
  967.     {
  968.     u_fprintf(OUT, " [<FONT SIZE=-1> ");
  969.  
  970.       for(n=0;n<(l->nSubLocs);n++)
  971.     {
  972.       printLocaleAndSubs(toOpen, &(l->subLocs[n]), current, restored);
  973.     }
  974.       
  975.     u_fprintf(OUT, " </FONT SIZE=-1>]");
  976.     }
  977. }
  978.  
  979.  
  980. /* chooselocale --------------------------------------------------------------------------- */
  981. void chooseLocale(bool_t toOpen, const char *current, const char *restored)
  982. {
  983.   bool_t  hit = FALSE;
  984.   int32_t n, j;
  985.   UErrorCode status = U_ZERO_ERROR;
  986.  
  987.   u_fprintf(OUT, "<TABLE BORDER=2 CELLPADDING=2 CELLSPACING=2>\r\n");
  988.  
  989.   u_fprintf(OUT, "<TR><TD><B>%U</B></TD><TD><B>%U</B></TD></TR>\r\n",
  990.         FSWF("localeList_Locale", "Languages"),
  991.         FSWF("localeList_Sublocale", "Countries"));
  992.  
  993.   u_fprintf(OUT, "<TR><TD COLSPAN=2><A HREF=\"?_=%s\">%U</A></TD></TR>\r\n",
  994.         locales->str, locales->ustr); /* default */ 
  995.  
  996.   mySort(locales, &status, TRUE); /* need the whole thing sorted */
  997.  
  998.   for(n=0;n<locales->nSubLocs;n++)
  999.     {
  1000.       u_fprintf(OUT, "<TR>\r\n");
  1001.  
  1002.  
  1003.       hit = !strcmp(locales->subLocs[n].str,current);
  1004.  
  1005.       if(hit)
  1006.     {
  1007.       u_fprintf(OUT,"<TD VALIGN=TOP BGCOLOR=\"#FFDDDD\">");
  1008.     }
  1009.       else
  1010.     u_fprintf(OUT,"<TD VALIGN=TOP>");
  1011.  
  1012.       if(hit)  
  1013.     u_fprintf(OUT, "<b>");
  1014.       
  1015.       
  1016.       printLocaleLink(toOpen, &(locales->subLocs[n]), current, restored);
  1017.  
  1018.       if(hit)
  1019.     u_fprintf(OUT, "</b>");
  1020.       
  1021.       u_fprintf(OUT, "</FONT>");
  1022.  
  1023.       u_fprintf(OUT, "</TD>");
  1024.       
  1025.       if(locales->subLocs[n].nSubLocs)
  1026.     {
  1027.       u_fprintf(OUT, "<TD>");
  1028.       
  1029.       for(j=0;j< (locales->subLocs[n].nSubLocs); j++)
  1030.         {
  1031.           if(j>0)
  1032.         u_fprintf(OUT, ", ");
  1033.           
  1034.           printLocaleAndSubs(toOpen, &(locales->subLocs[n].subLocs[j]), current, restored);
  1035.           
  1036.         }
  1037.  
  1038.       u_fprintf(OUT, "</TD>");
  1039.     }
  1040.  
  1041.       u_fprintf(OUT, "</TR>\r\n");
  1042.  
  1043.  
  1044.     }
  1045.  
  1046.   u_fprintf(OUT, "</TABLE>\r\n");
  1047. }
  1048.  
  1049.  
  1050. /* chooseconverter ----------------------------------------------------------------------------- */
  1051. void chooseConverter(const char *restored)
  1052. {
  1053.   int32_t  ncnvs;
  1054.   int32_t  i;
  1055.   int32_t  COLS = 8; /* number of columns */
  1056.   int32_t rows;
  1057.   const char *cnvMime, *defaultMime;
  1058.  
  1059.   defaultMime = MIMECharsetName(ucnv_getDefaultName());
  1060.  
  1061.   
  1062.  if(!restored)
  1063.     restored = "";
  1064.  
  1065.   u_fprintf(OUT,"<A HREF=\"?%s\"><H2>%U%s%U</H2></A>\r\n",
  1066.          restored,
  1067.          FSWF("encodingOK0", "Click here if the encoding '"),
  1068.          ucnv_getDefaultName(),
  1069.          FSWF("encodingOK1", "' is acceptable, or choose one from below."));
  1070.  
  1071.  
  1072.   ncnvs = ucnv_countAvailable();
  1073.  
  1074.   u_fprintf_u(OUT, FSWF("convsAvail","%d converters available."), ncnvs);
  1075.  
  1076.   rows = (ncnvs / COLS) + 1;
  1077.  
  1078.   u_fprintf(OUT, "<P><TABLE cellpadding=3 cellspacing=2 >\r\n"
  1079.              "<TR>\r\n");
  1080.  
  1081.   for(i=0;i<(rows * COLS);i++)
  1082.     {
  1083.       int32_t theCell;
  1084.       bool_t hit;
  1085.       const char *cnv = NULL; 
  1086.       
  1087.  
  1088.       u_fprintf(OUT, "<!-- %d -->", i);
  1089.  
  1090.       theCell=(rows * (i%COLS)) + (i/COLS); 
  1091.       if(theCell >= ncnvs)
  1092.     {
  1093.       u_fprintf(OUT,"<td></td>");
  1094.       if(((i+1)%COLS) == 0)
  1095.         u_fprintf(OUT,"</TR>\n<TR>");
  1096.       continue;
  1097.     }
  1098.  
  1099.       cnv = (const char *)ucnv_getAvailableName(theCell);
  1100.  
  1101.       if(!cnv)
  1102.     continue;
  1103.  
  1104.       /*      if(!cnv)
  1105.     {
  1106.       fprintf(stderr,"**************** END OF CNVS AT %d\n", i); fflush(stderr);
  1107.       return;
  1108.       } */
  1109.       cnvMime = MIMECharsetName(cnv);
  1110.  
  1111.       hit = !strcmp(cnvMime, defaultMime);
  1112.  
  1113.       if(hit)
  1114.     u_fprintf(OUT,"<TD BGCOLOR=\"#FFDDDD\">");
  1115.       else
  1116.     u_fprintf(OUT,"<TD>");
  1117.  
  1118.       u_fprintf(OUT, "<FONT SIZE=-1>");
  1119.  
  1120.       if(hit)  
  1121.     u_fprintf(OUT, "<b>");
  1122.       
  1123.       u_fprintf(OUT, "<A HREF=\"");
  1124.  
  1125.  
  1126.       u_fprintf(OUT, "%s/%s/",
  1127.         getenv("SCRIPT_NAME"),
  1128.         uloc_getDefault());
  1129.       u_fprintf(OUT,"%s/", cnv);
  1130.       if(restored)
  1131.     u_fprintf(OUT, "?%s", restored); 
  1132.       
  1133.       u_fprintf(OUT,"\">");
  1134.       u_fprintf(OUT, "%s", MIMECharsetName(cnv));
  1135.       /*       theCnvale.getDisplayName(o.GetLocale(),tmp); */
  1136.       u_fprintf(OUT,"</A>\n");
  1137.       
  1138.       if(hit)
  1139.     u_fprintf(OUT, "</b>");
  1140.       
  1141.       u_fprintf(OUT, "</FONT>");
  1142.       u_fprintf(OUT, "</FONT>");
  1143.       u_fprintf(OUT, "</TD>");
  1144.       if(((i+1)%COLS) == 0)
  1145.     u_fprintf(OUT, "</TR>\n<TR>");
  1146.     }
  1147.   u_fprintf(OUT,"</TABLE>\r\n");
  1148.  
  1149.  
  1150.   { /* Todo: localize */
  1151.     const char *ts = "??";
  1152.     UErrorCode status;
  1153.     char tmp[100];
  1154.     UConverter *u = u_fgetConverter(OUT);
  1155.     
  1156.  
  1157.     status = U_ZERO_ERROR;
  1158.  
  1159.     u_fprintf(OUT,"<HR>");
  1160.     u_fprintf(OUT,"<H3>Information about <B><TT>%s</TT></B></H3>\r\n",
  1161.           ucnv_getName(u, &status));
  1162.     u_fprintf(OUT,"<UL>");
  1163.     
  1164.     u_fprintf(OUT,"  <LI>ID = %d, platform=%s\n",
  1165.           ucnv_getCCSID(u,&status),
  1166.           (ucnv_getPlatform(u,&status) == UCNV_IBM) ? "IBM" : "other");
  1167.        
  1168.           
  1169.     u_fprintf(OUT,"  <LI>min/max chars: %d to %d\n",
  1170.           ucnv_getMinCharSize(u),
  1171.           ucnv_getMaxCharSize(u));
  1172.  
  1173.     u_fprintf(OUT,"  <LI>Type=");
  1174.     switch(ucnv_getType(u))
  1175.       {
  1176.       case UCNV_UNSUPPORTED_CONVERTER:  ts = "Unsupported"; break;
  1177.       case UCNV_SBCS: ts = "Single Byte Character Set"; break;
  1178.       case UCNV_DBCS: ts = "Double Byte Character Set"; break;
  1179.       case UCNV_MBCS: ts = "Multiple Byte Character Set (variable)"; break;
  1180.       case UCNV_LATIN_1: ts = "Latin-1"; break;
  1181.       case UCNV_UTF8: ts = "UTF-8 (8 bit unicode)"; break;
  1182.       case UCNV_UTF16_BigEndian: ts = "UTF-16 Big Endian"; break;
  1183.       case UCNV_UTF16_LittleEndian: ts = "UTF-16 Little Endian"; break;
  1184.       case UCNV_EBCDIC_STATEFUL: ts = "EBCDIC Stateful"; break;
  1185.       case UCNV_ISO_2022: ts = "iso-2022 meta-converter"; break;
  1186.       case UCNV_JIS: ts = "JIS (Japan Industrial Society?)"; break;
  1187.       case UCNV_EUC: ts = "EUC"; break; /* ? */
  1188.       case UCNV_GB: ts = "GB"; break; /* ? */
  1189.       default: ts = tmp; sprintf(tmp, "Unknown type %d", ucnv_getType(u));
  1190.       }
  1191.     u_fprintf(OUT, "%s\n", ts);
  1192.  
  1193.     u_fprintf(OUT, "<A TARGET=unibrowse HREF=\"/cgi-bin/unibrowse.sh/%s/\">Browse Unicode in this codepage</A>\r\n", defaultMime);
  1194.     
  1195.     u_fprintf(OUT, "</UL>\r\n");
  1196.   }
  1197.           
  1198. }
  1199.  
  1200.   /*  Main function for dumping the contents of a particular locale ---------------------------- */
  1201.  
  1202. void listBundles(char *b)
  1203. {
  1204.   char *tmp, *locale = NULL;
  1205.   UChar myChars[1024];
  1206.   UErrorCode status = U_ZERO_ERROR;
  1207.   UResourceBundle *myRB = NULL;
  1208.   bool_t doShowSort = FALSE;
  1209.  
  1210.   if(*b == '_')
  1211.     {
  1212.       b++;
  1213.       
  1214.       if(*b == '=')
  1215.     {
  1216.       
  1217.       b++;
  1218.       
  1219.       tmp =strchr(b,'&');
  1220.       if(tmp)
  1221.         { 
  1222.           *tmp = 0;
  1223.         }
  1224.       
  1225.       locale = b;
  1226.  
  1227.       if(tmp)
  1228.         {
  1229.           b = tmp;
  1230.           b++;
  1231.         }
  1232.     }
  1233.     }
  1234.  
  1235.  
  1236.   if(! locale )
  1237.     {
  1238.       chooseLocale(TRUE, b, "");
  1239.       return;
  1240.     }
  1241.  
  1242.   u_fprintf(OUT, "<TABLE BORDER=0 CELLSPACING=2>\r\n");
  1243.  
  1244.   u_fprintf(OUT, "<TR><TD COLSPAN=2>");
  1245.  
  1246.   u_fprintf(OUT, "<TD ALIGN=left>");
  1247.   
  1248.   myRB = ures_open(NULL, locale, &status);
  1249.   if(U_FAILURE(status))
  1250.     {
  1251.       u_fprintf(OUT,"</TR></TABLE><B>An error occured [%d] opening that resource bundle [%s]. Perhaps it doesn't exist? </B><P><HR>\r\n",status, locale);
  1252.       return;
  1253.     }
  1254.  
  1255.   explainStatus(status,"top");
  1256.  
  1257.   /*  showFlagImage(locale, " "); */
  1258.   /*   u_fprintf(OUT, "</TD></TR><TR><TD COLSPAN=2>"); */
  1259.  
  1260.   /* analyze what kind of locale we've got.  Should this be a little smarter? */
  1261.  
  1262. #if 0
  1263.   u_fprintf(OUT, "%U", FSWF("localeDataWhat", "This page shows the localization data for the locale listed at left. "));
  1264.  
  1265.   if(strlen(locale)==2) /* just the language */
  1266.     {
  1267.       u_fprintf(OUT, " %U",FSWF("localeDataLanguage","No country is specified, so the data is generic to this language."));
  1268.     }
  1269.   else if(!strcmp(locale,"default"))
  1270.     {
  1271.       u_fprintf(OUT, " %U", FSWF("localeDataDefault", "This is the default localization data, which will be used if no other installed locale is specified."));
  1272.     }
  1273.   else if(locale[2] == '_')
  1274.     {
  1275.       if(strlen(locale) == 5)
  1276.     {
  1277.        u_fprintf(OUT, " %U", FSWF("localeDataLangCountry", "This Locale contains data for this language, as well as conventions for this particular country."));
  1278.      }
  1279.        else
  1280.      {
  1281.       u_fprintf(OUT, " %U", FSWF("localeDataLangCountryVariant", "This Locale contains data for this language, as well as conventions for a variant within this particular country."));
  1282.     }
  1283.     }
  1284.  
  1285.   if(strstr(locale, "_EURO"))
  1286.     {
  1287.       u_fprintf(OUT, " %U", FSWF("localeDataEuro", "This Locale contains currency formatting information for use with the Euro currency."));
  1288.     }
  1289. #endif
  1290.   u_fprintf(OUT, "</TD></TR>\r\n");
  1291.  
  1292.   u_fprintf(OUT, "</TABLE>");
  1293.   
  1294.   status = U_ZERO_ERROR;
  1295.  
  1296.   /* Show the explore.. things first. ======================*/
  1297.   if(strstr(b,"EXPLORE_DateTimePatterns"))
  1298.     {
  1299.       showExploreDateTimePatterns(myRB, locale, b);
  1300.     }
  1301.  
  1302.   else if (strstr(b, "EXPLORE_NumberPatterns"))
  1303.     {
  1304.       showExploreNumberPatterns(locale, b);
  1305.     }
  1306.  
  1307.   else if (strstr(b, "EXPLORE_CollationElements"))
  1308.     {
  1309.       showKeyAndStartItem("EXPLORE_CollationElements", 
  1310.               FSWF("EXPLORE_CollationElements", "Collation (sorting) Example"),
  1311.               locale,
  1312.               U_ZERO_ERROR);
  1313.  
  1314. #if 0
  1315.       u_fprintf(OUT, "<A HREF=\"?_=%s#usort\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/opened.gif\" ALT=\"\"> %U</A>\r\n",
  1316.         locale,
  1317.         kStaticURLPrefix,
  1318.         FSWF("usortHide", "Hide this example"));
  1319. #endif
  1320.       
  1321.       u_fprintf(OUT, "%U<P>", FSWF("usortWhat","This example demonstrates sorting (collation) in this locale."));
  1322.       showSort(locale, b);
  1323.       
  1324.       u_fprintf(OUT, "</TD>");
  1325.  
  1326.       u_fprintf(OUT, "<TD VALIGN=TOP ALIGN=RIGHT>");
  1327.       printHelpTag("EXPLORE_CollationElements", NULL);
  1328.       u_fprintf(OUT, "</TD>");
  1329.  
  1330. #if 0
  1331.       if(!strstr(usort))
  1332.     {
  1333.       u_fprintf(OUT, "<A HREF=\"?_=%s&usort&_#usort\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/closed.gif\" ALT=\"\"> %U</A>\r\n",
  1334.             locale,
  1335.             kStaticURLPrefix,
  1336.             FSWF("usortShow", "Show this example"));
  1337.       
  1338.       
  1339.       u_fprintf(OUT, "<BR>%U</TD>",
  1340.             FSWF("usortWhat","This example demonstrates sorting (collation) in this locale."));
  1341.     }
  1342. #endif
  1343.  
  1344.       showKeyAndEndItem("EXPLORE_CollationElements", locale);
  1345.     }
  1346.   else /* ================================= Normal ShowXXXXX calls ===== */
  1347.     {
  1348.       showLocaleCodes(myRB, locale);
  1349.       
  1350.       /* Now, a list of the things to show. */
  1351.       /*   showString(myRB, "Souffle"); */
  1352.       /* Let's organize these. */
  1353.       /* DATE/TIME */
  1354.       showShortLong(myRB, locale, "Day", 
  1355.             FSWF("DayAbbreviations", "Short Names"),
  1356.             FSWF("DayNames", "Long Names"),7);
  1357.       showShortLong(myRB, locale, "Month",
  1358.             FSWF("MonthAbbreviations", "Short Names"),
  1359.             FSWF("MonthNames", "Long Names"), 12);
  1360.  
  1361.       {
  1362.     const UChar *ampmDesc[3];
  1363.     ampmDesc[0] = FSWF("AmPmMarkers0", "am");
  1364.     ampmDesc[1] = FSWF("AmPmMarkers1", "pm");
  1365.     ampmDesc[2] = 0;
  1366.     
  1367.     showArrayWithDescription(myRB, locale, ampmDesc, "AmPmMarkers");
  1368.       }
  1369.  
  1370.  
  1371.       {
  1372.     const UChar *currDesc[4];
  1373.     currDesc[0] = FSWF("CurrencyElements0", "Currency symbol");
  1374.     currDesc[1] = FSWF("CurrencyElements1", "Int'l Currency symbol");
  1375.     currDesc[2] = FSWF("CurrencyElements2", "Currency separator");
  1376.     currDesc[3] = 0;
  1377.     
  1378.     showArrayWithDescription(myRB, locale, currDesc, "CurrencyElements");
  1379.       }
  1380.  
  1381.  
  1382.       {
  1383.     const UChar *dtpDesc[10]; /* flms */
  1384.     dtpDesc[0] = FSWF("DateTimePatterns0", "Full Time");
  1385.     dtpDesc[1] = FSWF("DateTimePatterns1", "Long Time");
  1386.     dtpDesc[2] = FSWF("DateTimePatterns2", "Medium Time");
  1387.     dtpDesc[3] = FSWF("DateTimePatterns3", "Short Time");
  1388.     dtpDesc[4] = FSWF("DateTimePatterns4", "Full Date");
  1389.     dtpDesc[5] = FSWF("DateTimePatterns5", "Long Date");
  1390.     dtpDesc[6] = FSWF("DateTimePatterns6", "Medium Date");
  1391.     dtpDesc[7] = FSWF("DateTimePatterns7", "Short Date");
  1392.     dtpDesc[8] = FSWF("DateTimePatterns8", "Date-Time pattern.<BR>{0} = time, {1} = date");
  1393.     dtpDesc[9] = 0;
  1394.  
  1395.     showArrayWithDescription(myRB, locale, dtpDesc, "DateTimePatterns");
  1396.       }
  1397.  
  1398.       showArray(myRB, locale, "Eras");
  1399.  
  1400.  
  1401.       { /*from dcfmtsym */
  1402.     const UChar *numDesc[12];
  1403.     numDesc[0] = FSWF("NumberElements0", "Decimal Separator");
  1404.     numDesc[1] = FSWF("NumberElements1", "Grouping Separator");
  1405.     numDesc[2] = FSWF("NumberElements2", "Pattern Separator");
  1406.     numDesc[3] = FSWF("NumberElements3", "Percent");
  1407.     numDesc[4] = FSWF("NumberElements4", "ZeroDigit");
  1408.     numDesc[5] = FSWF("NumberElements5", "Digit");
  1409.     numDesc[6] = FSWF("NumberElements6", "Minus Sign");
  1410.     numDesc[7] = FSWF("NumberElements7", "Exponential");
  1411.     numDesc[8] = FSWF("NumberElements8", "PerMill [/1000]");
  1412.     numDesc[9] = FSWF("NumberElements9", "Infinity");
  1413.     numDesc[10] = FSWF("NumberElements10", "Not a number");
  1414.     numDesc[11] = 0;
  1415.     showArrayWithDescription(myRB, locale, numDesc, "NumberElements");
  1416.       }
  1417.  
  1418.  
  1419.       { /*from dcfmtsym */
  1420.     const UChar *numDesc[5];
  1421.     numDesc[0] = FSWF("NumberPatterns0", "Decimal Pattern");
  1422.     numDesc[1] = FSWF("NumberPatterns1", "Currency Pattern");
  1423.     numDesc[2] = FSWF("NumberPatterns2", "Percent Pattern");
  1424.     numDesc[3] = FSWF("NumberPatterns3", "Scientific Pattern");
  1425.     numDesc[4] = 0;
  1426.  
  1427.     showArrayWithDescription(myRB, locale, numDesc, "NumberPatterns");
  1428.       }
  1429.  
  1430.       showDateTimeElements(myRB, locale);
  1431.  
  1432.       { 
  1433.     const UChar *zsDesc[6];
  1434.     zsDesc[0] = FSWF("zoneStrings0", "Canonical");
  1435.     zsDesc[1] = FSWF("zoneStrings1", "Normal Name");
  1436.     zsDesc[2] = FSWF("zoneStrings2", "Normal Abbrev");
  1437.     zsDesc[3] = FSWF("zoneStrings3", "Summer/DST Name");
  1438.     zsDesc[4] = FSWF("zoneStrings4", "Summer/DST Abbrev");
  1439.     zsDesc[5] = FSWF("zoneStrings5", "Example City");
  1440.     zsDesc[6] = 0;
  1441.  
  1442.     show2dArrayWithDescription(myRB, locale, zsDesc, b, "zoneStrings");
  1443.       }
  1444.       /*
  1445.     'NOT USED IN ICU'
  1446.     show2dArray(myRB, locale, b, "LocaleNamePatterns");
  1447.       */
  1448.  
  1449.  
  1450.       /* locale pattern chars */
  1451.       {
  1452.     const UChar *charDescs[19];
  1453.  
  1454.     charDescs[0] = FSWF("localPatternChars0", "Era");
  1455.     charDescs[1] = FSWF("localPatternChars1", "Year");
  1456.     charDescs[2] = FSWF("localPatternChars2", "Month");
  1457.     charDescs[3] = FSWF("localPatternChars3", "Date");
  1458.     charDescs[4] = FSWF("localPatternChars4", "Hour Of Day 1");
  1459.     charDescs[5] = FSWF("localPatternChars5", "Hour Of Day 0"); 
  1460.     charDescs[6] = FSWF("localPatternChars6", "Minute");
  1461.     charDescs[7] = FSWF("localPatternChars7", "Second");
  1462.     charDescs[8] = FSWF("localPatternChars8", "Millisecond");
  1463.     charDescs[9] = FSWF("localPatternChars9", "Day Of Week");
  1464.     charDescs[10] = FSWF("localPatternChars10", "Day Of Year");
  1465.     charDescs[11] = FSWF("localPatternChars11", "Day Of Week In Month");
  1466.     charDescs[12] = FSWF("localPatternChars12", "Week Of Year");
  1467.     charDescs[13] = FSWF("localPatternChars13", "Week Of Month");
  1468.     charDescs[14] = FSWF("localPatternChars14", "Am/Pm");
  1469.     charDescs[15] = FSWF("localPatternChars15", "Hour 1");
  1470.     charDescs[16] = FSWF("localPatternChars16", "Hour 0");
  1471.     charDescs[17] = FSWF("localPatternChars17", "Timezone");
  1472.     charDescs[18] = 0;
  1473.     
  1474.     showStringWithDescription(myRB, locale, b, charDescs, "localPatternChars", TRUE);
  1475.       }
  1476.  
  1477.       /* COLLATION */
  1478.       showCollationElements(myRB, locale, b, "CollationElements");
  1479.  
  1480.       /* LOCALE */
  1481.       showString(myRB, locale, b, "LocaleID");
  1482.  
  1483.       /*
  1484.     'NOT USED IN THE ICU'
  1485.  
  1486.     showString(myRB, locale, b, "LocaleString");
  1487.       */
  1488.  
  1489.       showTaggedArray(myRB, locale, b, "Languages");
  1490.       showTaggedArray(myRB, locale, b, "Countries"); 
  1491.  
  1492.   /* GENERAL */
  1493.       showString(myRB, locale, b, "Version");
  1494.   
  1495.       /* Todo:
  1496.      "%%B"    /    "%%NY"     - NO variants. ???
  1497.  
  1498.      "%%EURO"   -- ?
  1499.      
  1500.       */     
  1501.  
  1502.     }
  1503.   /* have to have this at the end */
  1504.   /*  u_fprintf(OUT, kItemTrailer); */
  1505.  
  1506.  
  1507.   /*   u_fprintf(OUT, "</TABLE>\r\n"); */
  1508.   
  1509.   ures_close(myRB);
  1510.  
  1511. }
  1512.  
  1513.  
  1514. /* Show a resource that's a collation rule list -----------------------------------------------------*/
  1515. /**
  1516.  * Show a string.  Make it progressive disclosure if it exceeds some length !
  1517.  * @param rb the resourcebundle to pull junk out of 
  1518.  * @param locale the name of the locale (for URL generation)
  1519.  * @param queryString the querystring of the request.
  1520.  * @param key the key we're listing
  1521.  */
  1522.  
  1523. void showCollationElements( UResourceBundle *rb, const char *locale, const char *queryString, const char *key )
  1524. {
  1525.   
  1526.   UErrorCode status = U_ZERO_ERROR;
  1527.   const UChar *s  = 0;
  1528.         UChar *comps = 0;
  1529.   bool_t bigString = FALSE; /* is it big? */
  1530.   bool_t userRequested = FALSE; /* Did the user request this string? */
  1531.   const char *tmp1, *tmp2;
  1532.   int32_t len;
  1533.  
  1534.   s = ures_get(rb, key, &status);
  1535.  
  1536.   if(!s || !s[0] || (status == U_MISSING_RESOURCE_ERROR))
  1537.     {
  1538.       UCollator *coll;
  1539.  
  1540.       /* Special case this to fetch what REALLY happens in this case ! */
  1541.       status = U_ZERO_ERROR;
  1542.  
  1543.       coll = ucol_open(locale, &status);
  1544.       if(U_SUCCESS(status))
  1545.     {
  1546.       s = ucol_getRules(coll, &len);
  1547.  
  1548.       ucol_close(coll);
  1549.     }
  1550.  
  1551.       /* fix the status */
  1552.       if(!strcmp(locale, "default"))
  1553.     status = U_ZERO_ERROR;
  1554.       else
  1555.     status = U_USING_DEFAULT_ERROR;
  1556.     }
  1557.   else
  1558.     len = u_strlen(s);
  1559.  
  1560.   if(U_SUCCESS(status) && ( len > kShowStringCutoffSize ) )
  1561.     {
  1562.       bigString = TRUE;
  1563.       userRequested = didUserAskForKey(key, queryString);
  1564.     }
  1565.  
  1566.   showKeyAndStartItemShort(key, NULL, locale, status);
  1567.  
  1568.   u_fprintf(OUT, "</TD></TR><TR><TD></TD><TD>");
  1569.   
  1570.   /* Ripped off from ArrayWithDescription. COPY BACK */
  1571.   
  1572.   showExploreButton(rb,locale,
  1573.             FSWF("EXPLORE_CollationElements_sampleString","bad\\u000DBad\\u000DBat\\u000Dbat\\u000Db\\u00E4d\\u000DB\\u00E4d\\u000Db\\u00E4t\\u000DB\\u00E4t"),
  1574.             "CollationElements");
  1575.  
  1576.  
  1577.  
  1578.   u_fprintf(OUT, "</TD>"); /* Now, we're done with the ShowKey.. cell */
  1579.  
  1580.  
  1581.  
  1582.   u_fprintf(OUT, "</TR><TR><TD COLSPAN=2>");
  1583.  
  1584.  
  1585.   if(U_SUCCESS(status))
  1586.     {
  1587.  
  1588.       if(bigString && !userRequested) /* it's hidden. */
  1589.     {
  1590.       /* WIERD!! outputting '&#' through UTF8 seems to be -> '?' or something 
  1591.          [duh, HTML numbered escape sequence] */
  1592.       u_fprintf(OUT, "<A HREF=\"?_=%s&SHOW%s&_#%s\"><IMG BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"%s/localeexplorer/closed.gif\" ALT=\"\">%U</A>\r\n<P>", locale, key,key, kStaticURLPrefix, FSWF("bigStringClickToShow","(Omitted due to size. Click here to show.)"));
  1593.       u_fprintf(OUT, "</TD><TD></TD>");
  1594.     }
  1595.       else
  1596.     {
  1597.       if(bigString)
  1598.         {
  1599.           u_fprintf(OUT, "<A HREF=\"?_=%s#%s\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/opened.gif\" ALT=\"\"> %U</A><P>\r\n",
  1600.             locale,
  1601.             key,
  1602.             kStaticURLPrefix,
  1603.             FSWF("bigStringHide", "Hide"));
  1604.         }
  1605.       
  1606.       if(U_SUCCESS(status))
  1607.         {
  1608.           
  1609.           comps = malloc(sizeof(UChar) * (len*2));
  1610.  
  1611.  
  1612.           len = u_normalize(s,
  1613.               len,
  1614.               UCOL_DECOMP_COMPAT_COMP_CAN,
  1615.               0,
  1616.               comps,
  1617.               len*2,
  1618.               &status);
  1619.  
  1620.  
  1621.           if(*comps == 0)
  1622.         {
  1623.           u_fprintf(OUT, "<I>%U</I>", FSWF("empty", "(Empty)"));
  1624.         }
  1625.           else while(len--)
  1626.         {
  1627.           
  1628.           if(*comps == '&')
  1629.             u_fprintf(OUT, "<P>");
  1630.           else if(*comps == '<')
  1631.             u_fprintf(OUT, "<BR> ");
  1632.           
  1633.           if((*comps == 0x000A) || u_isprint(*comps))
  1634.             u_fprintf(OUT, "%K", *comps);
  1635.           else
  1636.             u_fprintf(OUT, "<B>\\u%04X</B>", *comps); /* to emulate the callback */
  1637.           
  1638.           comps++;
  1639.         };
  1640.         }
  1641.       else
  1642.         explainStatus(status, key);
  1643.     }
  1644.     }
  1645.   u_fprintf(OUT, "</TD>");
  1646.   
  1647.   showKeyAndEndItem(key, locale);
  1648. }
  1649.  
  1650.  
  1651. void showLocaleCodes( UResourceBundle *rb, const char *locale)
  1652. {
  1653.   
  1654.   UErrorCode status = U_ZERO_ERROR;
  1655.   bool_t bigString = FALSE; /* is it big? */
  1656.   bool_t userRequested = FALSE; /* Did the user request this string? */
  1657.   const char *tmp1, *tmp2;
  1658.   char tempchar[1000];
  1659.  
  1660.   UErrorCode countStatus = U_ZERO_ERROR,langStatus = U_ZERO_ERROR;
  1661.   const UChar *count3 = 0, *lang3 = 0;
  1662.  
  1663.   count3 = ures_get(rb, "ShortCountry", &countStatus);
  1664.   lang3 = ures_get(rb, "ShortLanguage", &langStatus);
  1665.  
  1666.  
  1667.   showKeyAndStartItem("LocaleCodes", FSWF("LocaleCodes", "Locale Codes"), locale, status);
  1668.  
  1669.   u_fprintf(OUT, "<TABLE BORDER=1><TR><TD></TD><TD><B>%U</B></TD><TD><B>%U</B></TD><TD><B>%U</B></TD></TR>\r\n",
  1670.         FSWF("LocaleCodes_Language", "Language"),
  1671.         FSWF("LocaleCodes_Country", "Country"),
  1672.         FSWF("LocaleCodes_Variant", "Variant"));
  1673.   u_fprintf(OUT, "<TR><TD>%U</TD><TD>",
  1674.         FSWF("LocaleCodes_2", "2"));
  1675.   
  1676.   status = U_ZERO_ERROR;
  1677.   uloc_getLanguage(locale, tempchar, 1000, &status);
  1678.   if(U_SUCCESS(status))
  1679.     u_fprintf(OUT, tempchar);
  1680.   else
  1681.     explainStatus(status, "LocaleCodes");
  1682.   
  1683.   u_fprintf(OUT, "</TD><TD>");
  1684.   
  1685.   status = U_ZERO_ERROR;
  1686.   uloc_getCountry(locale, tempchar, 1000, &status);
  1687.   if(U_SUCCESS(status))
  1688.     u_fprintf(OUT, tempchar);
  1689.   else
  1690.     explainStatus(status, "LocaleCodes");
  1691.   
  1692.   u_fprintf(OUT, "</TD><TD>");
  1693.   
  1694.   status = U_ZERO_ERROR;
  1695.   uloc_getVariant(locale, tempchar, 1000, &status);
  1696.   if(U_SUCCESS(status))
  1697.     u_fprintf(OUT, tempchar);
  1698.   else
  1699.     explainStatus(status, "LocaleCodes");
  1700.  
  1701.   u_fprintf(OUT, "</TD></TR>\r\n");
  1702.  
  1703.   /* 3 letter line */
  1704.  
  1705.   u_fprintf(OUT, "<TR><TD>%U</TD>",
  1706.         FSWF("LocaleCodes_3", "3"));
  1707.  
  1708.   u_fprintf(OUT, "<TD>");
  1709.  
  1710.   if(U_SUCCESS(langStatus))
  1711.     {
  1712.       u_fprintf(OUT, "%U", lang3);
  1713.       if(langStatus != U_ZERO_ERROR)
  1714.     {
  1715.       u_fprintf(OUT, "<BR>");
  1716.     }
  1717.     }
  1718.  
  1719.   explainStatus(langStatus, "LocaleCodes");
  1720.  
  1721.   u_fprintf(OUT, "</TD><TD>");
  1722.  
  1723.   if(U_SUCCESS(countStatus))
  1724.     {
  1725.       u_fprintf(OUT, "%U", count3);
  1726.       if(countStatus != U_ZERO_ERROR)
  1727.     {
  1728.       u_fprintf(OUT, "<BR>");
  1729.     }
  1730.     }
  1731.  
  1732.   explainStatus(countStatus, "LocaleCodes");
  1733.  
  1734.   u_fprintf(OUT, "</TD><TD></TD></TR>\r\n");
  1735.   
  1736.   u_fprintf(OUT, "</TABLE>\r\n");
  1737.  
  1738.  
  1739.   u_fprintf(OUT, "</TD>");
  1740.   showKeyAndEndItem("LocaleCodes", locale);
  1741. }
  1742.  
  1743.  
  1744. /* Show a resource that's a simple string -----------------------------------------------------*/
  1745. /**
  1746.  * Show a string.  Make it progressive disclosure if it exceeds some length !
  1747.  * @param rb the resourcebundle to pull junk out of 
  1748.  * @param locale the name of the locale (for URL generation)
  1749.  * @param queryString the querystring of the request.
  1750.  * @param key the key we're listing
  1751.  */
  1752.  
  1753. void showString( UResourceBundle *rb, const char *locale, const char *queryString, const char *key )
  1754. {
  1755.   
  1756.   UErrorCode status = U_ZERO_ERROR;
  1757.   const UChar *s  = 0;
  1758.   bool_t bigString = FALSE; /* is it big? */
  1759.   bool_t userRequested = FALSE; /* Did the user request this string? */
  1760.   const char *tmp1, *tmp2;
  1761.  
  1762.   s = ures_get(rb, key, &status);
  1763.  
  1764.   if(U_SUCCESS(status) && ( u_strlen(s) > kShowStringCutoffSize ) )
  1765.     {
  1766.       bigString = TRUE;
  1767.       userRequested = didUserAskForKey(key, queryString);
  1768.     }
  1769.  
  1770.   showKeyAndStartItem(key, NULL, locale, status);
  1771.  
  1772.  
  1773.   if(U_SUCCESS(status))
  1774.     {
  1775.  
  1776.       if(bigString && !userRequested) /* it's hidden. */
  1777.     {
  1778.       /* WIERD!! outputting '&#' through UTF8 seems to be -> '?' or something 
  1779.          [duh, HTML numbered escape sequence] */
  1780.       u_fprintf(OUT, "<A HREF=\"?_=%s&SHOW%s&_#%s\"><IMG BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"%s/localeexplorer/closed.gif\" ALT=\"\">%U</A>\r\n<P>", locale, key,key, kStaticURLPrefix, FSWF("bigStringClickToShow","(Omitted due to size. Click here to show.)"));
  1781.     }
  1782.       else
  1783.     {
  1784.       if(bigString)
  1785.         {
  1786.           u_fprintf(OUT, "<A HREF=\"?_=%s#%s\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/opened.gif\" ALT=\"\"> %U</A><P>\r\n",
  1787.             locale,
  1788.             key,
  1789.             kStaticURLPrefix,
  1790.             FSWF("bigStringHide", "Hide"));
  1791.         }
  1792.       
  1793.       if(U_SUCCESS(status))
  1794.         {
  1795.           if(*s == 0)
  1796.         u_fprintf(OUT, "<I>%U</I>", FSWF("empty", "(Empty)"));
  1797.           else
  1798.         u_fprintf(OUT, "%U ", s);
  1799.         }
  1800.     }
  1801.     }
  1802.   u_fprintf(OUT, "</TD>");
  1803.   showKeyAndEndItem(key, locale);
  1804. }
  1805.  
  1806. /* Show a resource that's a simple string, but explain each character.-----------------------------------------------------*/
  1807. /**
  1808.  * Show a string.  Make it progressive disclosure if it exceeds some length !
  1809.  * @param rb the resourcebundle to pull junk out of 
  1810.  * @param locale the name of the locale (for URL generation)
  1811.  * @param queryString the querystring of the request.
  1812.  * @param desc array (0 at last item) of char desc
  1813.  * @param key the key we're listing
  1814.  */
  1815.  
  1816. void showStringWithDescription(UResourceBundle *rb, const char *locale, const char *qs, const UChar *desc[], const char *key, bool_t hidable)
  1817. {
  1818.   
  1819.   UErrorCode status = U_ZERO_ERROR;
  1820.   const UChar *s  = 0;
  1821.   bool_t bigString = FALSE; /* is it big? */
  1822.   bool_t userRequested = FALSE; /* Did the user request this string? */
  1823.   const char *tmp1, *tmp2;
  1824.   int32_t i;
  1825.  
  1826.   s = ures_get(rb, key, &status);
  1827.  
  1828.   /* we'll assume it's always big, for now. */
  1829.   bigString = TRUE;
  1830.   userRequested = didUserAskForKey(key, qs);
  1831.  
  1832.   showKeyAndStartItem(key, NULL, locale, status);
  1833.  
  1834.   /** DON'T show the string as a string. */
  1835.   /* 
  1836.      if(U_SUCCESS(status) && s)
  1837.      u_fprintf(OUT, "%U<BR>\r\n", s);
  1838.   */
  1839.   if(!hidable)
  1840.     {
  1841.       userRequested = TRUE;
  1842.       bigString = FALSE;
  1843.     }
  1844.   
  1845.  
  1846.   if(bigString && !userRequested) /* it's hidden. */
  1847.     {
  1848.       /* WIERD!! outputting '&#' through UTF8 seems to be -> '?' or something */
  1849.     u_fprintf(OUT, "<A HREF=\"?_=%s&SHOW%s&_#%s\"><IMG BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"%s/localeexplorer/closed.gif\" ALT=\"\">%U</A>\r\n<P>", locale, key,key, kStaticURLPrefix, FSWF("stringClickToShow","(Click here to show.)"));
  1850.     u_fprintf(OUT, "<P>");
  1851.     }
  1852.   else
  1853.     {
  1854.       if(bigString)
  1855.     {
  1856.       u_fprintf(OUT, "<A HREF=\"?_=%s#%s\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/opened.gif\" ALT=\"\"> %U</A><P>\r\n",
  1857.             locale,
  1858.             key,
  1859.         kStaticURLPrefix,
  1860.             FSWF("bigStringHide", "Hide"));
  1861.     }
  1862.   
  1863.       if(U_SUCCESS(status))
  1864.     {
  1865.       u_fprintf(OUT, "<TABLE BORDER=1 WIDTH=100%>");
  1866.       u_fprintf(OUT, "<TR><TD><B>%U</B></TD><TD><B>%U</B></TD><TD><B>%U</B></TD></TR>\r\n",
  1867.             FSWF("charNum", "#"),
  1868.             FSWF("char", "Char"),
  1869.             FSWF("charMeaning", "Meaning"));
  1870.       
  1871.       
  1872.       for(i=0;desc[i];i++)
  1873.         {
  1874.           if(!s[i])
  1875.         break;
  1876.           
  1877.           u_fprintf(OUT, "<TR><TD WIDTH=5>%d</TD><TD>%K</TD><TD>%U</TD></TR>\r\n",
  1878.                i,
  1879.             s[i],
  1880.                desc[i]);
  1881.         }
  1882.       u_fprintf(OUT, "</TABLE>\r\n");
  1883.     }
  1884.     }
  1885.   u_fprintf(OUT, "</TD>");
  1886.   showKeyAndEndItem(key, locale);
  1887. }
  1888.   
  1889. /* Show a resource that's an array. Useful for types we haven't written viewers for yet --------*/
  1890.  
  1891. void showArray( UResourceBundle *rb, const char *locale, const char *key )
  1892. {
  1893.   UErrorCode status = U_ZERO_ERROR;
  1894.   UErrorCode firstStatus = U_ZERO_ERROR;
  1895.   const UChar *s  = 0;
  1896.   int i;
  1897.  
  1898.   ures_getArrayItem(rb, key, 0, &firstStatus);
  1899.  
  1900.   showKeyAndStartItem(key, NULL, locale, firstStatus);
  1901.  
  1902.   u_fprintf(OUT, "<OL>\r\n");
  1903.  
  1904.   for(i=0;;i++)
  1905.     {
  1906.       status = U_ZERO_ERROR;
  1907.  
  1908.       s = ures_getArrayItem(rb, key, i, &status);
  1909.       if(!s)
  1910.     break;
  1911.  
  1912.       if(U_SUCCESS(status))
  1913.     u_fprintf(OUT, "<LI> %U\r\n", s);
  1914.       else
  1915.     {
  1916.       u_fprintf(OUT, "<LI>");
  1917.       explainStatus(status, key);
  1918.       u_fprintf(OUT, "\r\n");
  1919.       break;
  1920.     }
  1921.  
  1922.     }
  1923.   u_fprintf(OUT, "</OL></TD>");
  1924.   showKeyAndEndItem(key, locale);
  1925. }
  1926.  
  1927.  
  1928. /* Show a resource that's an array, wiht an explanation ------------------------------- */
  1929.  
  1930. void showArrayWithDescription( UResourceBundle *rb, const char *locale, const UChar *desc[], const char *key )
  1931. {
  1932.   UErrorCode status = U_ZERO_ERROR;
  1933.   UErrorCode firstStatus;
  1934.   const UChar *s  = 0, *toShow =0;
  1935.   enum { kNoExample = 0, kDateTimeExample, kNumberExample } exampleType;
  1936.   int32_t i;
  1937.   UDate now;  /* example date */
  1938.   double d = 1234.567;   /* example number */
  1939.   UDateFormat   *exampleDF = 0;
  1940.   UNumberFormat *exampleNF = 0;
  1941.   UErrorCode exampleStatus = U_ZERO_ERROR;
  1942.   UChar tempChars[1024];
  1943.   UChar tempDate[1024]; /* for Date-Time */
  1944.   UChar tempTime[1024]; /* for Date-Time */
  1945.   int32_t len = 0;
  1946.  
  1947.   /* figure out what example to use */
  1948.   if(!strcmp(key,"DateTimePatterns"))
  1949.     exampleType = kDateTimeExample;
  1950.   else if(!strcmp(key, "NumberPatterns"))
  1951.     exampleType = kNumberExample;
  1952.   else
  1953.     exampleType = kNoExample;
  1954.  
  1955.   /* store the date now..just in case formatting takes multiple seconds! */
  1956.   now = ucal_getNow();
  1957.  
  1958.   firstStatus = U_ZERO_ERROR;
  1959.   s = ures_getArrayItem(rb, key, 0, &firstStatus);
  1960.   showKeyAndStartItemShort(key, NULL, locale, firstStatus);
  1961.  
  1962.   if(exampleType != kNoExample)
  1963.     {
  1964.       toShow = (UChar[]){ 0x0000 };
  1965.       exampleStatus = U_ZERO_ERROR;
  1966.  
  1967.       switch(exampleType)
  1968.     {
  1969.  
  1970.     case kDateTimeExample:
  1971.       exampleStatus = U_ZERO_ERROR;
  1972.       exampleDF = udat_openPattern(s,-1,locale,&exampleStatus);
  1973.       if(U_SUCCESS(exampleStatus))
  1974.         {
  1975.           len = udat_toPattern(exampleDF, TRUE, tempChars, 1024,&exampleStatus);
  1976.           if(U_SUCCESS(exampleStatus))
  1977.         {
  1978.           toShow = tempChars;
  1979.         }
  1980.         }
  1981.       break;
  1982.       
  1983.     case kNumberExample:
  1984.       toShow = (UChar[]){ 0x00B3,0x0000 }; /* # */
  1985.       exampleNF = unum_openPattern(s,-1,locale,&exampleStatus);
  1986.       if(U_SUCCESS(exampleStatus))
  1987.         {
  1988.           len = unum_toPattern(exampleNF, TRUE, tempChars, 1024, &exampleStatus);
  1989.           if(U_SUCCESS(exampleStatus))
  1990.         {
  1991.           toShow = tempChars;
  1992.         }
  1993.           unum_close(exampleNF);
  1994.         }
  1995.       break;
  1996.     }
  1997.       exampleStatus = U_ZERO_ERROR;
  1998.  
  1999.       showExploreButton(rb, locale, toShow, key);
  2000.     }
  2001.  
  2002.   u_fprintf(OUT, "</TD>"); /* Now, we're done with the ShowKey.. cell */
  2003.  
  2004.  
  2005.   u_fprintf(OUT, "</TR><TR><TD COLSPAN=2><TABLE BORDER=2 WIDTH=\"100%\" HEIGHT=\"100%\">\r\n");
  2006.  
  2007.   for(i=0;desc[i];i++)
  2008.     {
  2009.       
  2010.       u_fprintf(OUT, "<TR><TD WIDTH=5>%d</TD><TD>%U</TD><TD>",
  2011.         i, desc[i]);
  2012.  
  2013.       status = U_ZERO_ERROR;
  2014.       exampleStatus = U_ZERO_ERROR;
  2015.  
  2016.       s = ures_getArrayItem(rb, key, i, &status);
  2017.  
  2018.       if(i==0)
  2019.     firstStatus = status;
  2020.  
  2021.       
  2022.       if(U_SUCCESS(status) && s)
  2023.     {
  2024.       toShow = s;
  2025.  
  2026.       switch(exampleType)
  2027.         {
  2028.         case kDateTimeExample: /* localize pattern.. */
  2029.           if(i < 8)
  2030.         {
  2031.           len = 0;
  2032.  
  2033.           exampleDF = udat_openPattern(s,-1,locale,&exampleStatus);
  2034.           if(U_SUCCESS(exampleStatus))
  2035.             {
  2036.               len = udat_toPattern(exampleDF, TRUE, tempChars, 1024,&exampleStatus);
  2037.  
  2038.               if(U_SUCCESS(exampleStatus))
  2039.             {
  2040.               toShow = tempChars;
  2041.             }
  2042.             }       
  2043.         }
  2044.           break;
  2045.  
  2046.         case kNumberExample:
  2047.           if(i == 3) /* scientific */
  2048.         d = 1234567890;
  2049.  
  2050.           exampleNF = unum_openPattern(s,-1,locale,&exampleStatus);
  2051.           if(U_SUCCESS(exampleStatus))
  2052.         {
  2053.           len = unum_toPattern(exampleNF, TRUE, tempChars, 1024, &exampleStatus);
  2054.           if(U_SUCCESS(exampleStatus))
  2055.             {
  2056.               toShow = tempChars;
  2057.             }
  2058.         }
  2059.           break;
  2060.  
  2061.           
  2062.         default:
  2063.         }
  2064.       
  2065.       u_fprintf(OUT, "%U\r\n", toShow);
  2066.     }
  2067.       else
  2068.     {
  2069.       s = 0;
  2070.       explainStatus(status, key);
  2071.       u_fprintf(OUT, "\r\n");
  2072.       break;
  2073.     }
  2074.       u_fprintf(OUT, "</TD>");
  2075.       
  2076.       if(s) /* only if pattern exists */
  2077.       switch(exampleType)
  2078.     {
  2079.     case kDateTimeExample:
  2080.       if(i < 8)
  2081.       {
  2082.         u_fprintf(OUT, "<TD>");
  2083.  
  2084.         if(U_SUCCESS(exampleStatus))
  2085.           {
  2086.         exampleStatus = U_ZERO_ERROR; /* clear fallback info from exampleDF */
  2087.         udat_format(exampleDF, now, tempChars, 1024, NULL, &exampleStatus);
  2088.         udat_close(exampleDF);
  2089.         
  2090.         if(U_SUCCESS(exampleStatus))
  2091.           u_fprintf(OUT, "%U", tempChars);
  2092.  
  2093.           }
  2094.         explainStatus(exampleStatus, key);
  2095.         u_fprintf(OUT, "</TD>\r\n");
  2096.  
  2097.         if(i == 3) /* short time */
  2098.           u_strcpy(tempTime, tempChars);
  2099.         else if(i == 7) /* short date */
  2100.           u_strcpy(tempDate, tempChars);
  2101.       }
  2102.       else
  2103.       {
  2104.         u_fprintf(OUT, "<TD>");
  2105.         exampleStatus = U_ZERO_ERROR;
  2106.         if(s)
  2107.           if(u_formatMessage(locale, s, -1, tempChars,1024,&exampleStatus, 
  2108.                  tempTime,
  2109.                  tempDate))
  2110.         u_fprintf(OUT,"%U", tempChars);
  2111.         u_fprintf(OUT, "</TD>\r\n");
  2112.       }
  2113.       break;
  2114.  
  2115.     case kNumberExample:
  2116.       {
  2117.         u_fprintf(OUT, "<TD>");
  2118.  
  2119.         if(U_SUCCESS(exampleStatus))
  2120.           {
  2121.         exampleStatus = U_ZERO_ERROR; /* clear fallback info from exampleDF */
  2122.  
  2123.          if(i == 3) /* scientific */
  2124.           d = 1234567890;
  2125.         unum_formatDouble(exampleNF, d, tempChars, 1024, NULL, &exampleStatus);
  2126.         
  2127.         if(U_SUCCESS(exampleStatus))
  2128.           u_fprintf(OUT, "%U", tempChars);
  2129.  
  2130.         
  2131.         u_fprintf(OUT, "</TD><TD>");
  2132.  
  2133.          if(i == 3) /* scientific */
  2134.           d = 0.00000000000000000005;
  2135.  
  2136.         unum_formatDouble(exampleNF, -d, tempChars, 1024, NULL, &exampleStatus);
  2137.         
  2138.         if(U_SUCCESS(exampleStatus))
  2139.           u_fprintf(OUT, "%U", tempChars);
  2140.  
  2141.         unum_close(exampleNF);
  2142.  
  2143.           }
  2144.         explainStatus(exampleStatus, key);
  2145.         u_fprintf(OUT, "</TD>\r\n");
  2146.       }
  2147.       break;
  2148.  
  2149.     case kNoExample:
  2150.     default:
  2151.       break;
  2152.     }
  2153.  
  2154.       u_fprintf(OUT, "</TR>\r\n");
  2155.  
  2156.     }
  2157.   
  2158.  
  2159.   u_fprintf(OUT, "</TABLE></TD>");
  2160.  
  2161.   showKeyAndEndItem(key, locale);
  2162. }
  2163.  
  2164.  
  2165. /* show the DateTimeElements string *------------------------------------------------------*/
  2166.  
  2167. void showDateTimeElements( UResourceBundle *rb, const char *locale)
  2168. {
  2169.   UErrorCode status = U_ZERO_ERROR;
  2170.   UErrorCode firstStatus;
  2171.   const UChar *s  = 0;
  2172.  
  2173.   const char *key = "DateTimeElements";
  2174.   int i;
  2175.   /*
  2176.     0: first day of the week 
  2177.     1: minimaldaysinfirstweek 
  2178.   */
  2179.  
  2180.   status = U_ZERO_ERROR;
  2181.  
  2182.   s = ures_getArrayItem(rb, key, 0, &status);
  2183.  
  2184.   showKeyAndStartItem(key, FSWF(key, "Date and Time Options"), locale, status);
  2185.  
  2186.   /* First day of the week ================= */
  2187.   u_fprintf(OUT, "%U ", FSWF("DateTimeElements0", "First day of the week: "));
  2188.   
  2189.  
  2190.   if(U_SUCCESS(status))
  2191.     {
  2192.       UChar myWkday[100];
  2193.       int32_t  firstDay;
  2194.  
  2195.       firstDay = (((s[0] & 0x000F)+6)%7); /* REVISIT: parse */
  2196.       
  2197.       u_fprintf(OUT, " %U \r\n", s);
  2198.       /* here's something fun: try to fetch that day from the user's current locale */
  2199.       status = U_ZERO_ERROR;
  2200.       
  2201.       if(defaultRB && U_SUCCESS(status))
  2202.     {
  2203.       s = ures_getArrayItem(defaultRB, "DayNames", firstDay, &status);
  2204.       if(s && U_SUCCESS(status))
  2205.         {
  2206.           u_fprintf(OUT, " = %U \r\n", s);
  2207.         }
  2208.       status = U_ZERO_ERROR;
  2209.  
  2210.       s = ures_getArrayItem(rb, "DayNames", firstDay , &status);
  2211.       if(s && U_SUCCESS(status))
  2212.         {
  2213.           u_fprintf(OUT, " = %U \r\n", s);
  2214.         }
  2215.  
  2216.  
  2217.     }
  2218.       status = U_ZERO_ERROR;
  2219.     }
  2220.   else
  2221.     {
  2222.       explainStatus(status, key);
  2223.       u_fprintf(OUT, "\r\n");
  2224.     }
  2225.  
  2226.  
  2227.   u_fprintf(OUT, "<BR>\r\n");
  2228.  
  2229.   /* minimal days in week ================= */
  2230.   u_fprintf(OUT, "%U", FSWF("DateTimeElements1", "Minimal Days in First Week: "));
  2231.   
  2232.   status = U_ZERO_ERROR;
  2233.  
  2234.   s = ures_getArrayItem(rb, key, 1, &status);
  2235.  
  2236.   firstStatus = status;
  2237.   
  2238.   if(U_SUCCESS(status))
  2239.     u_fprintf(OUT, " %U \r\n", s);
  2240.   else
  2241.     {
  2242.       explainStatus(status, key);
  2243.       u_fprintf(OUT, "\r\n");
  2244.     }
  2245.  
  2246.   u_fprintf(OUT, "</TD>");
  2247.  
  2248.   showKeyAndEndItem(key, locale);
  2249. }
  2250.  
  2251. /* Show a resource that has a short (*Abbreviations) and long (*Names) version ---------------- */
  2252. /* modified showArray */
  2253. void showShortLong( UResourceBundle *rb, const char *locale, const char *keyStem, const UChar *shortName, const UChar *longName, int32_t num )
  2254. {
  2255.   UErrorCode status = U_ZERO_ERROR;
  2256.   UErrorCode shortStatus = U_ZERO_ERROR, longStatus = U_ZERO_ERROR;
  2257.   char       shortKey[100], longKey[100];
  2258.   const UChar *s  = 0;
  2259.   int i;
  2260.  
  2261.   showKeyAndStartItem(keyStem, NULL, locale, U_ZERO_ERROR); /* No status possible  because we have two items */
  2262.  
  2263.   sprintf(shortKey, "%sNames", keyStem);
  2264.   sprintf(longKey,  "%sAbbreviations", keyStem);
  2265.  
  2266.   /* pre load the status of these things */
  2267.   ures_getArrayItem(rb,longKey, 0, &longStatus);
  2268.   ures_getArrayItem(rb,shortKey, 0, &shortStatus);
  2269.  
  2270.   u_fprintf(OUT, "<TABLE BORDER=1 WIDTH=100%% HEIGHT=100%%><TR><TD><B>#</B></TD><TD><B>%U</B> ", shortName);
  2271.   explainStatus(shortStatus, keyStem);
  2272.   u_fprintf(OUT, "</TD><TD><B>%U</B> ", longName);
  2273.   explainStatus(longStatus, keyStem);
  2274.   u_fprintf(OUT, "</TD></TR>\r\n");
  2275.  
  2276.  
  2277.   for(i=0;i<num;i++)
  2278.     {
  2279.       char *key;
  2280.  
  2281.       u_fprintf(OUT, " <TR><TD>%d</TD><TD>", i);
  2282.  
  2283.       /* get the normal name */
  2284.       status = U_ZERO_ERROR;
  2285.       key = longKey;
  2286.       s = ures_getArrayItem(rb, key, i, &status);
  2287.  
  2288.       if(i==0)
  2289.     longStatus = status;
  2290.   
  2291.       if(U_SUCCESS(status))
  2292.     u_fprintf(OUT, " %U ", s);
  2293.       else
  2294.     explainStatus(status, keyStem); /* if there was an error */
  2295.  
  2296.       u_fprintf(OUT, "</TD><TD>");
  2297.  
  2298.       /* get the short name */
  2299.       status = U_ZERO_ERROR;
  2300.       key = shortKey;
  2301.       s = ures_getArrayItem(rb, key, i, &status);
  2302.  
  2303.       if(i==0)
  2304.     shortStatus = status;
  2305.   
  2306.       if(U_SUCCESS(status))
  2307.     u_fprintf(OUT, " %U ", s);
  2308.       else
  2309.     explainStatus(status, keyStem); /* if there was an error */
  2310.  
  2311.       u_fprintf(OUT, "</TD></TR>");
  2312.     }
  2313.  
  2314.   u_fprintf(OUT, "</TABLE>");
  2315.   u_fprintf(OUT, "</TD>");
  2316.  
  2317.   showKeyAndEndItem(keyStem, locale);
  2318.  
  2319. }
  2320.  
  2321. /* Show a 2d array  -------------------------------------------------------------------*/
  2322.  
  2323. void show2dArrayWithDescription( UResourceBundle *rb, const char *locale, const UChar *desc[], const char *queryString, const char *key )
  2324. {
  2325.   UErrorCode status = U_ZERO_ERROR;
  2326.   UErrorCode firstStatus;
  2327.   const UChar *s  = 0;
  2328.   int32_t h,v;
  2329.   int32_t rows,cols;
  2330.   bool_t bigString = FALSE; /* is it big? */
  2331.   bool_t userRequested = FALSE; /* Did the user request this string? */
  2332.   const char *tmp1, *tmp2;
  2333.  
  2334.   ures_count2dArrayItems(rb, key, &rows, &cols, &status);
  2335.  
  2336.   if(U_SUCCESS(status) && ((rows > kShow2dArrayRowCutoff) || (cols > kShow2dArrayColCutoff)) )
  2337.     {
  2338.       bigString = TRUE;
  2339.       userRequested = didUserAskForKey(key, queryString);
  2340.     }
  2341.  
  2342.   showKeyAndStartItem(key, NULL, locale, status);
  2343.  
  2344.  
  2345.   if(bigString && !userRequested) /* it's hidden. */
  2346.     {
  2347.       /* WIERD!! outputting '&#' through UTF8 seems to be -> '?' or something */
  2348.     u_fprintf(OUT, "<A HREF=\"?_=%s&SHOW%s&_#%s\"><IMG BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"%s/localeexplorer/closed.gif\" ALT=\"\">%U</A>\r\n<P>", locale, key,key, kStaticURLPrefix, FSWF("bigStringClickToShow","(Omitted due to size. Click here to show.)"));
  2349.     }
  2350.   else
  2351.     {
  2352.       if(bigString)
  2353.     {
  2354.       u_fprintf(OUT, "<A HREF=\"?_=%s#%s\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/opened.gif\" ALT=\"\"> %U</A><P>\r\n",
  2355.             locale,
  2356.             key,
  2357.             kStaticURLPrefix,
  2358.             FSWF("bigStringHide", "Hide"));
  2359.     }
  2360.  
  2361.       firstStatus = status;  /* save this for the next column.. */
  2362.  
  2363.       if(U_SUCCESS(status))
  2364.     {    
  2365.  
  2366.  
  2367.       u_fprintf(OUT,"<TABLE BORDER=1>\r\n");
  2368.       
  2369.       /* print the top row */
  2370.       u_fprintf(OUT,"<TR><TD></TD>");
  2371.       for(h=0;h<cols;h++)
  2372.         {
  2373.           if(!desc[h])
  2374.         break;
  2375.  
  2376.           u_fprintf(OUT,"<TD><B>%U</B></TD>", desc[h]);
  2377.         }
  2378.       u_fprintf(OUT,"</TR>\r\n");
  2379.       
  2380.       for(v=0;v<rows;v++)
  2381.         {
  2382.           u_fprintf(OUT,"<TR><TD><B>%d</B></TD>", v);
  2383.           for(h=0;h<cols;h++)
  2384.         {
  2385.           status = U_ZERO_ERROR;
  2386.           
  2387.           s = ures_get2dArrayItem(rb, key, v, h, &status);
  2388.           
  2389.           /*      if((h == 0) && (v==0))
  2390.               firstStatus = status; */ /* Don't need to track firstStatus, countArrayItems should do that for us. */
  2391.           
  2392.           if(U_SUCCESS(status) && s)
  2393.             u_fprintf(OUT, "<TD>%U</TD>\r\n", s);
  2394.           else
  2395.             {
  2396.               u_fprintf(OUT, "<TD BGCOLOR=" kStatusBG " VALIGN=TOP>");
  2397.               explainStatus(status, key);
  2398.               u_fprintf(OUT, "</TD>\r\n");
  2399.               break;
  2400.             }
  2401.         }
  2402.           u_fprintf(OUT, "</TR>\r\n");
  2403.         }
  2404.       u_fprintf(OUT, "</TABLE>\r\n<BR>");
  2405.     }
  2406.     }
  2407.  
  2408.   showKeyAndEndItem(key, locale);
  2409. }
  2410.  
  2411. /* Show a Tagged Array  -------------------------------------------------------------------*/
  2412.  
  2413. void showTaggedArray( UResourceBundle *rb, const char *locale, const char *queryString, const char *key )
  2414. {
  2415.   UErrorCode status = U_ZERO_ERROR;
  2416.   UErrorCode firstStatus;
  2417.   const UChar *s  = 0;
  2418.   UChar displayName[1024];
  2419.   int32_t v;
  2420.   int32_t rows;
  2421.   bool_t bigString = FALSE; /* is it big? */
  2422.   bool_t userRequested = FALSE; /* Did the user request this string? */
  2423.   const char *tmp1, *tmp2;
  2424.  
  2425.   rows = ures_countArrayItems(rb, key, &status);
  2426.  
  2427.   if(U_SUCCESS(status) && ((rows > kShow2dArrayRowCutoff)))
  2428.     {
  2429.       bigString = TRUE;
  2430.       userRequested = didUserAskForKey(key, queryString);
  2431.     }
  2432.  
  2433.   showKeyAndStartItem(key, NULL, locale, status);
  2434.  
  2435.   if(bigString && !userRequested) /* it's hidden. */
  2436.     {
  2437.       /* WIERD!! outputting '&#' through UTF8 seems to be -> '?' or something */
  2438.     u_fprintf(OUT, "<A HREF=\"?_=%s&SHOW%s&_#%s\"><IMG BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"%s/localeexplorer/closed.gif\" ALT=\"\">%U</A>\r\n<P>", locale, key,key, kStaticURLPrefix, FSWF("bigStringClickToShow","(Omitted due to size. Click here to show.)"));
  2439.     }
  2440.   else
  2441.     {
  2442.       if(bigString)
  2443.     {
  2444.       u_fprintf(OUT, "<A HREF=\"?_=%s#%s\"><IMG border=0 width=16 height=16 SRC=\"%s/localeexplorer/opened.gif\" ALT=\"\"> %U</A><P>\r\n",
  2445.             locale,
  2446.             key,
  2447.             kStaticURLPrefix,
  2448.             FSWF("bigStringHide", "Hide"));
  2449.     }
  2450.  
  2451.       firstStatus = status;  /* save this for the next column.. */
  2452.  
  2453.       if(U_SUCCESS(status))
  2454.     {    
  2455.       
  2456.  
  2457.       u_fprintf(OUT,"<TABLE BORDER=1>\r\n");
  2458.       
  2459.       /* print the top row */
  2460.       u_fprintf(OUT,"<TR><TD><B>%U</B></TD><TD><I>%U</I></TD><TD><B>%U</B></TD></TR>",
  2461.             FSWF("taggedarrayTag", "Tag"),
  2462.             defaultLanguageDisplayName(),
  2463.             curLocale->ustr);
  2464.       
  2465.       for(v=0;v<rows;v++)
  2466.         {
  2467.           const char *tag;
  2468.  
  2469.           status = U_ZERO_ERROR;
  2470.           
  2471.           tag = ures_getTaggedArrayTag(rb, key, v, &status);
  2472.           if(!tag)
  2473.         break;
  2474.           
  2475.           u_fprintf(OUT,"<TR> ");
  2476.  
  2477.           if(U_SUCCESS(status))
  2478.         {
  2479.           u_fprintf(OUT, "<TD><TT>%s</TT></TD> ", tag);
  2480.           
  2481.           if(defaultRB)
  2482.             {
  2483.               s = ures_getTaggedArrayItem(defaultRB, key, tag, &status);
  2484.               if(s)
  2485.             u_fprintf(OUT, "<TD><I>%U</I></TD>", s);
  2486.               else
  2487.             u_fprintf(OUT, "<TD></TD>");
  2488.             }
  2489.               else
  2490.             u_fprintf(OUT, "<TD></TD>");
  2491.           
  2492.           status = U_ZERO_ERROR;
  2493.  
  2494.           s = ures_getTaggedArrayItem(rb, key, tag, &status);
  2495.  
  2496.           if(s)
  2497.             u_fprintf(OUT, "<TD>%U</TD>", s);
  2498.           else
  2499.             {
  2500.               u_fprintf(OUT, "<TD BGCOLOR=" kStatusBG " VALIGN=TOP>");
  2501.               explainStatus(status, key);
  2502.               u_fprintf(OUT, "</TD>\r\n");
  2503.             }
  2504.         }
  2505.           u_fprintf(OUT, "</TR>\r\n");
  2506.         }
  2507.       u_fprintf(OUT, "</TABLE>\r\n<BR>");
  2508.     }
  2509.     }
  2510.  
  2511.   u_fprintf(OUT, "</TD>");
  2512.   showKeyAndEndItem(key, locale);
  2513. }
  2514.  
  2515.  
  2516. /* Explain what the status code means --------------------------------------------------------- */
  2517.  
  2518. void explainStatus( UErrorCode status, const char *tag )
  2519. {
  2520.   if(tag == 0)
  2521.     tag = "_top_";
  2522.  
  2523.   u_fprintf(OUT, " <B><FONT SIZE=-1>");
  2524.   switch(status)
  2525.     {
  2526.     case U_MISSING_RESOURCE_ERROR:
  2527.       printHelpTag("U_MISSING_RESOURCE_ERROR",
  2528.            FSWF("U_MISSING_RESOURCE_ERROR", "(missing resource)"));
  2529.       break;
  2530.  
  2531.     case U_USING_FALLBACK_ERROR:
  2532.       if(parLocale && parLocale->str)
  2533.     {
  2534.       u_fprintf(OUT, "<A HREF=\"?_=%s#%s\">", parLocale->str, tag);
  2535.       u_fprintf_u(OUT, FSWF("inherited_from", "(inherited from %U)"), parLocale->ustr); 
  2536.     }
  2537.       else
  2538.     {
  2539.       u_fprintf(OUT, "<A HREF=\"?_=default#%s\">", tag);
  2540.       u_fprintf_u(OUT, FSWF("inherited", "(inherited)"));
  2541.     }
  2542.  
  2543.       u_fprintf(OUT, "</A>");
  2544.       break;
  2545.  
  2546.     case U_USING_DEFAULT_ERROR:
  2547.     u_fprintf(OUT, "<A HREF=\"?_=default#%s\">", tag);
  2548.       u_fprintf_u(OUT, FSWF("inherited_from", "(inherited from %U)"), locales->ustr); 
  2549.       u_fprintf(OUT, "</A>");
  2550.       break;
  2551.  
  2552.     default:
  2553.       if(status != U_ZERO_ERROR)
  2554.     {
  2555.       u_fprintf(OUT, "(%U %d)", FSWF("UNKNOWN_ERROR", "unknown error"), (int) status);
  2556.       fprintf(stderr,"LRB: caught Unknown err- %d\n", status); 
  2557.     }
  2558.     }
  2559.   u_fprintf(OUT, "</FONT></B>");
  2560. }
  2561.  
  2562.  
  2563. bool_t didUserAskForKey(const char *key, const char *queryString)
  2564. {
  2565.   const char *tmp1, *tmp2;
  2566.   
  2567.   tmp1 = strstr(queryString, "SHOW");
  2568.   
  2569.   /* look to see if they asked for it */
  2570.   if(tmp1)
  2571.     {
  2572.       tmp1 += 4;
  2573.       
  2574.       tmp2 = strchr(tmp1,'&'); /*look for end of that field */
  2575.       if(!tmp2)
  2576.     tmp2 = tmp1 + strlen(tmp1); /* no end in sight */
  2577.       
  2578.       
  2579.       if(!strncmp(tmp1, key, (tmp2-tmp1)))
  2580.     {
  2581.       return TRUE;
  2582.     }
  2583.     }
  2584.   return FALSE;
  2585. }
  2586.  
  2587. /* Convenience function.  print <A HREF="..."> for a link to the correct Help page.  if str=null it defaults to Help*/
  2588.  
  2589. void printHelpTag(const char *helpTag, const UChar *str)
  2590. {
  2591.   if(str == NULL)
  2592.     {
  2593.       /* str = FSWF("help", "Help"); */
  2594.       
  2595.       printHelpImg(helpTag, FSWF("help", "Help"), 
  2596.            FSWF("helpgif", "help.gif"),
  2597.            FSWF("helpgif_opt", "BORDER=0"));
  2598.       return;
  2599.  
  2600.     }
  2601.  
  2602.   u_fprintf(OUT, "<SCRIPT LANGUAGE=\"JavaScript\">");
  2603.   u_fprintf(OUT, "<!--\r\n  top.document.write('<A HREF=\\\"javascript:openHelpWin(\\'%s/localeexplorer/%Uhelp.html#%s\\', \\'%s\\')\\\" >%U</A>');\r\n",
  2604.         kStaticURLPrefix,
  2605.         FSWF("helpPrefix", "default_"),
  2606.         helpTag, helpTag, str);
  2607.   u_fprintf(OUT, "// -->\r\n</SCRIPT>\r\n");
  2608.   u_fprintf(OUT, "<NOSCRIPT>\r\n");
  2609.   u_fprintf(OUT, "<A HREF=\"%s/localeexplorer/%Uhelp.html#%s\" TARGET=\"help\">%U</A></NOSCRIPT>",
  2610.         kStaticURLPrefix,
  2611.         FSWF("helpPrefix", "default_"),
  2612.         helpTag,str);
  2613. }
  2614.  
  2615. void printHelpImg(const char *helpTag, const UChar *alt, const UChar *src, const UChar *options)
  2616. {
  2617.   u_fprintf(OUT, "<SCRIPT LANGUAGE=\"JavaScript\">");
  2618.   u_fprintf(OUT, "<!--\r\n  top.document.write('");
  2619.   u_fprintf(OUT, "<A HREF=\\\"javascript:openHelpWin(\\'%s/localeexplorer/%Uhelp.html#%s\\', \\'%s\\')\\\" ><IMG %U SRC=\\\"%s/localeexplorer/%U\\\" ALT=\\\"%U\\\"></A>",
  2620.         kStaticURLPrefix,
  2621.         FSWF("helpPrefix", "default_"),
  2622.         helpTag, 
  2623.         helpTag,
  2624.         options, kStaticURLPrefix, src, alt);
  2625.   u_fprintf(OUT, "');\r\n// -->\r\n</SCRIPT>\r\n");
  2626.   u_fprintf(OUT, "<NOSCRIPT>\r\n");
  2627.   u_fprintf(OUT, "<A HREF=\"%s/localeexplorer/%Uhelp.html#%s\" TARGET=\"help\"><IMG %U SRC=\"%s/localeexplorer/%U\" ALT=\"%U\"></A>",
  2628.         kStaticURLPrefix,
  2629.         FSWF("helpPrefix", "default_"),
  2630.         helpTag, 
  2631.         options, kStaticURLPrefix, src, alt);
  2632.   u_fprintf(OUT, "</NOSCRIPT>\r\n");
  2633. }
  2634.  
  2635. void showExploreCloseButton(const char *locale, const char *frag)
  2636. {
  2637.   u_fprintf(OUT, "<!-- non javascript version first -->\r\n"
  2638.                  "<SCRIPT LANGUAGE=\"JavaScript\">");
  2639.   u_fprintf(OUT, "<!--\r\n   top.document.write('<B><I>When done, you may close this window</I></B>');\r\n// -->\r\n</SCRIPT>\r\n");
  2640.   u_fprintf(OUT, "<NOSCRIPT><FORM ACTION=\"#%s\">"
  2641.                  "<INPUT TYPE=HIDDEN NAME=\"_\" VALUE=\"%s\">"
  2642.              "<INPUT TYPE=SUBMIT VALUE=\"%U\" ONCLICK=\"window.close()\">"
  2643.                  "</FORM></NOSCRIPT>",
  2644.         frag, locale, FSWF("explore_close", "Done"));
  2645. }
  2646.  
  2647. void showExploreButton(UResourceBundle *rb, const char *locale, const UChar *sampleString, const char *key)
  2648. {
  2649.   UChar nullString[] = { 0x0000 };
  2650.   
  2651.   if(!sampleString)
  2652.     sampleString = nullString;
  2653.   
  2654.   /**   
  2655.     todo:
  2656.     
  2657.     
  2658.     <SCRIPT>
  2659.     ... non-javascript form ...
  2660.     
  2661.     
  2662.     <!-- 
  2663.     doc.write("javascript form");
  2664.     // -->
  2665.     </SCRIPT>
  2666.   **/
  2667. #if 0
  2668.   u_fprintf(OUT, "<SCRIPT LANGUAGE=\"JavaScript\">\r\n"
  2669.         "<!--\r\n"
  2670.         "  top.document.write('");
  2671.   
  2672.   /* replace with window.open */
  2673.   u_fprintf(OUT, "<FORM target=\\\"_new\\\" NAME=EXPLORE_%s ACTION=\"#EXPLORE_%s\">"
  2674.         "<INPUT TYPE=HIDDEN NAME=_ VALUE=\"%s\">"
  2675.         "<INPUT TYPE=HIDDEN NAME=\"EXPLORE_%s\" VALUE=\"",
  2676.         key, key,locale,key);
  2677.   writeEscaped(sampleString);
  2678.   u_fprintf(OUT, "\">");
  2679.   
  2680.   u_fprintf(OUT, "<INPUT TYPE=IMAGE WIDTH=48 HEIGHT=20 BORDER=0 SRC=/developerworks/opensource/icu/project/localeexplorer/explore.gif ALIGN=RIGHT   ");
  2681.   u_fprintf(OUT, " VALUE=\"%U\"></FORM>",
  2682.         FSWF("explore_Button", "Explore"));
  2683.  
  2684.   u_fprintf(OUT, "');\r\n//-->\r\n</SCRIPT>\r\n");
  2685.  
  2686.   /* ================ */
  2687.   
  2688.   u_fprintf(OUT, "<NOSCRIPT>\r\n");
  2689. #endif
  2690.   u_fprintf(OUT, "<FORM TARGET=\"_new\" NAME=EXPLORE_%s ACTION=\"#EXPLORE_%s\">"
  2691.         "<INPUT TYPE=HIDDEN NAME=_ VALUE=\"%s\">"
  2692.         "<INPUT TYPE=HIDDEN NAME=\"EXPLORE_%s\" VALUE=\"",
  2693.         key, key,locale,key);
  2694.   writeEscaped(sampleString);
  2695.   u_fprintf(OUT, "\">");
  2696.   
  2697.   u_fprintf(OUT, "<INPUT TYPE=IMAGE WIDTH=48 HEIGHT=20 BORDER=0 SRC=/developerworks/opensource/icu/project/localeexplorer/explore.gif  ALIGN=RIGHT   ");
  2698.   u_fprintf(OUT, " VALUE=\"%U\"></FORM>",
  2699.         FSWF("explore_Button", "Explore"));
  2700. #if 0
  2701.   u_fprintf(OUT, "</NOSCRIPT>\r\n");
  2702. #endif
  2703. }
  2704.  
  2705. void exploreFetchNextPattern(UChar *dstPattern, const char *qs)
  2706. {
  2707.  
  2708.   /* make QS point to the first char of the field data */
  2709.   qs = strchr(qs, '=');
  2710.   qs++;
  2711.  
  2712.   unescapeAndDecodeQueryField(dstPattern, 1000, qs);
  2713.   u_replaceChar(dstPattern, 0x0020, 0x00A0);
  2714. }
  2715.  
  2716. /**
  2717.  */
  2718.  
  2719. void exploreShowPatternForm(UChar *dstPattern, const char *locale, const char *key, const char* qs, double value, UNumberFormat *valueFmt)
  2720. {
  2721.   UChar *p;
  2722.   int32_t len;
  2723.   UErrorCode status = U_ZERO_ERROR;
  2724.   UChar tmp[1024];
  2725.  
  2726.   /**********  Now we've got the pattern from the user. Now for the form.. ***/
  2727.   u_fprintf(OUT, "<FORM METHOD=GET ACTION=\"#EXPLORE_%s\">\r\n",
  2728.         key);
  2729.   u_fprintf(OUT, "<INPUT NAME=_ TYPE=HIDDEN VALUE=%s>", locale);
  2730.  
  2731.   if(valueFmt)
  2732.     {
  2733.       
  2734.       u_fprintf(OUT, "<INPUT NAME=NP_DBL TYPE=HIDDEN VALUE=\"");
  2735.       tmp[0] = 0;
  2736.       unum_formatDouble(valueFmt, value, tmp, 1000, 0, &status);
  2737.       u_fprintf(OUT, "%U\">", tmp);
  2738.     }
  2739.   u_fprintf(OUT, "<TEXTAREA ROWS=2 COLS=60 NAME=\"EXPLORE_%s\">",
  2740.         key);
  2741.  
  2742.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE, &status); 
  2743.  
  2744.   u_fprintf(OUT, "%U", dstPattern); 
  2745.  
  2746.         /* should 'get/restore' here. */
  2747.   /*  ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &SubstituteWithValueHTML, &status); */
  2748.   ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);
  2749.  
  2750.   
  2751.   u_fprintf(OUT, "</TEXTAREA><P>\r\n<INPUT TYPE=SUBMIT VALUE=Format><INPUT TYPE=RESET VALUE=Reset></FORM>\r\n");
  2752.  
  2753. }
  2754.  
  2755.  
  2756. #ifdef kUSort
  2757.  
  2758. /* Demonstrate sorting ------------------------------------------------------------------------- */
  2759. /* locale to view, b is the rest of the querystring */
  2760.  
  2761. /* To demonstrate sorting, we are going to call the usort external program.
  2762.    This is a little simpler than maintaining two sets of code for doing sorting. 
  2763.    the real solution would be to modularize the code in usort.. 
  2764. */
  2765.  
  2766. void showSort(const char *locale, const char *b)
  2767. {
  2768.   char   inputChars[1024];
  2769.   char   tmpChars[1024];
  2770.   char *text;
  2771.   char *p;
  2772.   int32_t length;
  2773.   UChar  strChars[1024];
  2774.  
  2775.   /* Actually, we don't need to convert the input text to Unicode. the usort program will
  2776.      accept it in the specified charset.. */
  2777.  
  2778.   strChars[0] = 0;
  2779.  
  2780.   text = strstr(b, "EXPLORE_CollationElements");
  2781.   if(text)
  2782.     {
  2783.       text += 26;
  2784.  
  2785.       unescapeAndDecodeQueryField(strChars, 1000, text);
  2786.       
  2787.       p = strchr(text, '&');
  2788.       if(p) /* there is a terminating ampersand */
  2789.     length = p - text;
  2790.       else
  2791.     length = strlen(text);
  2792.  
  2793.       if(length > 1023)
  2794.     length = 1023; /* safety ! */
  2795.  
  2796.       doDecodeQueryField(text, inputChars, length); /* length limited */
  2797.     }
  2798.   else
  2799.     {
  2800.       inputChars[0] = 0; 
  2801.     }
  2802.  
  2803.   u_fprintf(OUT, "%U<P>\r\n", FSWF("EXPLORE_CollationElements_Prompt", "Type in some lines of text to be sorted."));
  2804.  
  2805.   u_fprintf(OUT, "<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1 WIDTH=100% HEIGHT=100%><TR><TD><B>%U</B></TD>\r\n",
  2806.         FSWF("usortSource", "Source"));
  2807.   
  2808.   if(inputChars[0])
  2809.     u_fprintf(OUT, "<TD><B>%U</B></TD><TD><B>%U</B></TD><TD><B>%U</B></TD>",
  2810.           FSWF("usortPrimary", "Primary"),
  2811.           FSWF("usortSecondary", "Secondary"),
  2812.           FSWF("usortTertiary", "Tertiary"));
  2813.   
  2814.   u_fprintf(OUT, "</TR><TR><TD VALIGN=TOP>");
  2815.  
  2816.   u_fprintf(OUT, "<FORM ACTION=\"#EXPLORE_CollationElements\" METHOD=GET>\r\n");
  2817.   u_fprintf(OUT, "<INPUT TYPE=HIDDEN NAME=\"_\" VALUE=\"%s\">\r\n", locale);
  2818.   u_fprintf(OUT, "<TEXTAREA ROWS=10 COLUMNS=25 COLS=40 NAME=\"EXPLORE_CollationElements\">");
  2819.  
  2820.   writeEscaped(strChars);
  2821.   /*  if(*inputChars)
  2822.       u_fprintf(OUT, "%s", inputChars); */
  2823.  
  2824.   u_fprintf(OUT, "</TEXTAREA><BR>\r\n");
  2825.  
  2826.   u_fprintf(OUT, "<INPUT TYPE=SUBMIT VALUE=\"%U\"></FORM><P>\r\n",
  2827.         FSWF("EXPLORE_CollationElements_Sort", "Sort"));
  2828.  
  2829.   u_fprintf(OUT, "</TD>");
  2830.  
  2831.   if(inputChars[0] != 0)
  2832.     {
  2833.       FILE *sortpipe;
  2834.       char sortTypes[4][10] = { "-1", "-2", "-3", "-I" };
  2835.       int n;
  2836.  
  2837.       /* have some text to sort */
  2838.  
  2839.       /* * set up the env vars */
  2840.       sprintf(tmpChars, "LANG=%s", locale);
  2841.       putenv(tmpChars);
  2842.  
  2843.       sprintf(tmpChars, "ICU_ENCODING=%s", ucnv_getDefaultName() );
  2844.       putenv(tmpChars);
  2845.  
  2846.  
  2847.       /* Loop through each sort method */
  2848.       for(n=0;n<3;n++) /* not 4 */
  2849.     {
  2850.       u_fprintf(OUT, " <TD><PRE>");
  2851.  
  2852.       sprintf(tmpChars, "%s -T %s %s %s ", kUSort, ourCharsetName, " -D -escape",  sortTypes[n]); /* pass the -escape string if they asked for it */
  2853.       
  2854.       fprintf(stderr, "OPENED: %s\n", tmpChars);
  2855.  
  2856.       sortpipe = popen(tmpChars, "w");
  2857.  
  2858.       if(!sortpipe)
  2859.         {
  2860.           u_fprintf(OUT, "<B>%U</B><BR>%s\r\n", FSWF("EXPLORE_CollationElements_PopenFailed", "Sorry, failed to popen the sort program!"), tmpChars);
  2861.         }
  2862.       else
  2863.         {
  2864.           fflush(stdout);
  2865.           fflush(stderr);
  2866.  
  2867.           fprintf(sortpipe, "%s\n", inputChars);
  2868.           fflush(sortpipe);
  2869.           pclose(sortpipe); /* that oughtta do it.. */
  2870.  
  2871.           fflush(stdout);
  2872.           fflush(stderr);
  2873.         } 
  2874.       u_fprintf(OUT, "</PRE></TD>");      
  2875.     }
  2876.     }
  2877.  
  2878.   u_fprintf(OUT, "</TR></TABLE><P>");
  2879.   u_fprintf(OUT, "<P><P>%U", FSWF("EXPLORE_CollationElements_strength", "There are four different strengths which may be used in collation.<P> Primary means that only primary differences are considered, such as letters. <P>Secondary considers letters, and also the secondary characteristics of accent marks. <P>Tertiary considers these two, and the case of the letter. <P> A strength of Identical means that all Unicode features are considered in determining a match."));
  2880.  
  2881.   u_fprintf(OUT, "<P>\r\n");
  2882.   showExploreCloseButton(locale, "CollationElements");
  2883.  
  2884. }
  2885.  
  2886. #endif /* kUSort */
  2887.  
  2888. /******************************************************************************
  2889.  *  Explorer for dates
  2890.  */
  2891.     
  2892. void showExploreDateTimePatterns(UResourceBundle *myRB, const char *locale, const char *b)
  2893. {
  2894.   UChar pattern[1024];
  2895.   UChar tempChars[1024];
  2896.   UChar defChars[1024];
  2897.   UChar valueString[1024];
  2898.   UDateFormat  *df = NULL, *df_default = NULL;
  2899.   UErrorCode   status = U_ZERO_ERROR, defStatus = U_ZERO_ERROR, locStatus = U_ZERO_ERROR;
  2900.   UDate now;  /* example date */
  2901.   UNumberFormat *nf = NULL; /* for formatting the number */
  2902.   char *tmp;
  2903.   int32_t parsePos = 0;
  2904.  
  2905.   nf = unum_openPattern(FSWF("EXPLORE_DateTimePatterns_dateAsNumber", "#"), -1, NULL, &status);
  2906.   status = U_ZERO_ERROR; /* ? */
  2907.   
  2908.   df_default = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, -1,  &status);
  2909.   status = U_ZERO_ERROR; /* ? */
  2910.  
  2911.   now = ucal_getNow();
  2912.   
  2913.   showKeyAndStartItem("EXPLORE_DateTimePatterns",
  2914.               FSWF("EXPLORE_DateTimePatterns", "Explore > Date/Time"),
  2915.               locale, U_ZERO_ERROR);
  2916.  
  2917.   u_fprintf(OUT, "%U<P>", FSWF("formatExample_DateTimePatterns_What","This example demonstrates the formatting of date and time patterns in this locale."));
  2918.   
  2919.   /* fetch the current pattern */
  2920.   exploreFetchNextPattern(pattern, strstr(b,"EXPLORE_DateTimePatterns"));
  2921.  
  2922.   df = udat_open(0,0,locale, NULL, -1, &status);
  2923.   udat_applyPattern(df, TRUE, pattern, -1);
  2924.  
  2925.   status = U_ZERO_ERROR;
  2926.   
  2927.   if (tmp = strstr(b,"NP_DBL")) /* Double: UDate format input ============= */
  2928.     {
  2929.       /* Localized # */
  2930.       tmp += 7;
  2931.  
  2932.       unescapeAndDecodeQueryField(valueString, 1000, tmp);
  2933.       u_replaceChar(valueString, 0x0020, 0x00A0);
  2934.  
  2935.       status = U_ZERO_ERROR;
  2936.       now = unum_parseDouble(nf, valueString, -1, &parsePos, &status);
  2937.     }
  2938.   else if(tmp = strstr(b, "NP_DEF")) /* Default: 'display' format input ============== */
  2939.     {
  2940.       int32_t q;
  2941.       UChar patn[1024];
  2942.  
  2943.       /* Localized # */
  2944.       tmp += 7;
  2945.  
  2946.       unescapeAndDecodeQueryField(valueString, 1000, tmp);
  2947.       /*      u_replaceChar(valueString, 0x0020, 0x00A0); */ /* NOt for the default pattern */
  2948.  
  2949. #if 0
  2950.       u_fprintf(OUT, "VS_=((");
  2951.       for(q=0;valueString[q];q++)
  2952.     {
  2953.       u_fprintf(OUT, "%c:%04x ", (char)valueString[q], valueString[q]);
  2954.     }
  2955.       u_fprintf(OUT, "))<BR>");
  2956.  
  2957.       udat_toPattern(df_default, FALSE, patn, 1024, &status);
  2958.  
  2959.       u_fprintf(OUT, "PAT=((");
  2960.       for(q=0;patn[q];q++)
  2961.     {
  2962.       u_fprintf(OUT, "%c:%04x ", (char)patn[q], patn[q]);
  2963.     }
  2964.       u_fprintf(OUT, "))<BR>");
  2965. #endif
  2966.  
  2967.       status = U_ZERO_ERROR;
  2968.       
  2969.       now = udat_parse(df_default, valueString, -1, &parsePos, &status);
  2970.     }
  2971.   else if(tmp = strstr(b, "NP_LOC")) /* Localized: pattern format input ============== */
  2972.     {
  2973.  
  2974.       int32_t q;
  2975.       UChar patn[1024];
  2976.  
  2977.       /* Localized # */
  2978.       tmp += 7;
  2979.  
  2980.       unescapeAndDecodeQueryField(valueString, 1000, tmp);
  2981.       u_replaceChar(valueString, 0x0020, 0x00A0); 
  2982.  
  2983.       /*      valueString[u_strlen(valueString)-1] = 0; */
  2984.           /* extra space ? */
  2985.  
  2986.  
  2987. #if 0
  2988.       u_fprintf(OUT, "VS_=((");
  2989.       for(q=0;valueString[q];q++)
  2990.     {
  2991.       u_fprintf(OUT, "%c:%04x ", (char)valueString[q], valueString[q]);
  2992.     }
  2993.       u_fprintf(OUT, "))<BR>");
  2994.  
  2995.       udat_toPattern(df, FALSE, patn, 1024, &status);
  2996.  
  2997.       u_fprintf(OUT, "PAT=((");
  2998.       for(q=0;patn[q];q++)
  2999.     {
  3000.       u_fprintf(OUT, "%c:%04x ", (char)patn[q], patn[q]);
  3001.     }
  3002.       u_fprintf(OUT, "))<BR>");
  3003. #endif
  3004.  
  3005.  
  3006.       status = U_ZERO_ERROR;
  3007.       now = udat_parse(df, valueString, -1, &parsePos, &status);
  3008.     }
  3009.  
  3010.   /* Common handler for input errs */
  3011.  
  3012.   if(U_FAILURE(status) || (now == 0))
  3013.     {
  3014.       status = U_ZERO_ERROR;
  3015.       u_fprintf(OUT, "%U %d<P>\r\n", FSWF("formatExample_errorParse", "Could not parse this, replaced with a default value. Formatted This many chars:"), parsePos);
  3016.       now = ucal_getNow();
  3017.     }
  3018.   status = U_ZERO_ERROR;
  3019.   /* ======================== End loading input date ================================= */
  3020.  
  3021.   if(U_FAILURE(status))
  3022.     {
  3023.       u_fprintf(OUT, "%U: [%d] <P>", FSWF("formatExample_DateTimePatterns_errorOpen", "Couldn't open the formatter"), (int) status);
  3024.       explainStatus(status, "EXPLORE_DateTimePatterns");
  3025.       exploreShowPatternForm(pattern, locale, "DateTimePatterns", strstr(b,"EXPLORE_DateTimePatterns"), now, nf);
  3026.     }
  3027.   else
  3028.     {
  3029.       
  3030.       /* now display the form */
  3031.       exploreShowPatternForm(pattern, locale, "DateTimePatterns", strstr(b,"EXPLORE_DateTimePatterns"), now, nf);
  3032.       
  3033.     }
  3034.   
  3035.   status = U_ZERO_ERROR;
  3036.   udat_format(df,now,tempChars, 1024, 0, &locStatus);
  3037.   udat_format(df_default,now,defChars, 1024, 0, &defStatus);
  3038.   
  3039.   if(U_FAILURE(status))
  3040.     u_fprintf(OUT, "%U<P>", FSWF("formatExample_DateTimePatterns_errorFormat", "Couldn't format the date"));
  3041.   
  3042.   explainStatus(status,"EXPLORE_DateTimePatterns");
  3043.  
  3044.  
  3045.  
  3046.   /* =======================  Now, collect the new date values ====================== */
  3047.  
  3048.   /* Now, display the results in <default> and in their locale */
  3049.   u_fprintf(OUT, "<TABLE BORDER=1><TR><TD>\r\n");
  3050.  
  3051.  
  3052.   /* ============ 'default' side of the table  */
  3053.  
  3054.   if(U_FAILURE(defStatus))
  3055.     {
  3056.       u_fprintf(OUT, "%U<P>", FSWF("formatExample_errorFormatDefault", "Unable to format number using default version of the pattern"));
  3057.       explainStatus(status, "EXPLORE_DateTimePatterns");
  3058.     }
  3059.   else
  3060.     {
  3061.       u_fprintf(OUT, "<B><I>%U</I></B><BR>\r\n", defaultLanguageDisplayName());
  3062. #if 0
  3063.       /* Just the pattern */
  3064.       u_fprintf(OUT, "%U", defChars);
  3065. #else
  3066.       u_fprintf(OUT, "<FORM METHOD=GET ACTION=\"#EXPLORE_DateTimePatterns\">\r\n");
  3067.       u_fprintf(OUT, "<INPUT NAME=_ TYPE=HIDDEN VALUE=%s>\r\n", locale);
  3068.       u_fprintf(OUT, "<INPUT TYPE=HIDDEN NAME=EXPLORE_DateTimePatterns VALUE=\"");
  3069.       writeEscaped(pattern);
  3070.       u_fprintf(OUT, "\">\r\n");
  3071.  
  3072.       u_fprintf(OUT, "<TEXTAREA NAME=NP_DEF ROWS=1 COLS=30>");
  3073.       ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE, &status); 
  3074.       u_fprintf(OUT, "%U", defChars); 
  3075.       
  3076.       /* should 'get/restore' here. */
  3077.       /*  ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &SubstituteWithValueHTML, &status); */
  3078.       ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);
  3079.  
  3080.       status = U_ZERO_ERROR;
  3081.       
  3082.       u_fprintf(OUT, "</TEXTAREA><BR><INPUT TYPE=SUBMIT VALUE=\"%U\"></FORM>", FSWF("EXPLORE_change", "Change"));
  3083. #endif
  3084.     }
  3085.   
  3086.   u_fprintf(OUT, "</TD><TD WIDTH=1 BGCOLOR=\"#EEEEEE\"><IMG SRC=/developerworks/opensource/icu/project/c.gif ALT=\"---\" WIDTH=0 HEIGHT=0></TD><TD>");
  3087.  
  3088.   /* ============ 'localized' side ================================= */
  3089.  
  3090.   if(U_FAILURE(locStatus))
  3091.     {
  3092.       u_fprintf(OUT, "%U<P>", FSWF("formatExample_errorFormatDate2", "Couldn't format the date normally"));
  3093.       explainStatus(status, "EXPLORE_DateTimePatterns");
  3094.     }
  3095.   else
  3096.     {
  3097.       /*  === local side */
  3098.       u_fprintf(OUT, "\r\n\r\n<!--  LOCALIZED SIDE -->\r\n<B>%U</B><BR>\r\n",curLocale?curLocale->ustr:FSWF("NoLocale","MISSING LOCALE NAME") );
  3099. #if 0
  3100.       u_fprintf(OUT, "%U", tempChars);
  3101. #else
  3102.       u_fprintf(OUT, "<FORM METHOD=GET ACTION=\"#EXPLORE_DateTimePatterns\">\r\n");
  3103.       u_fprintf(OUT, "<INPUT NAME=_ TYPE=HIDDEN VALUE=%s>\r\n", locale);
  3104.       u_fprintf(OUT, "<INPUT TYPE=HIDDEN NAME=EXPLORE_DateTimePatterns VALUE=\"");
  3105.       writeEscaped(pattern);
  3106.       u_fprintf(OUT, "\">\r\n");
  3107.       
  3108.       u_fprintf(OUT, "<TEXTAREA NAME=NP_LOC ROWS=1 COLS=30>");
  3109.       writeEscaped(tempChars);
  3110.       u_fprintf(OUT, "</TEXTAREA><BR><INPUT TYPE=SUBMIT VALUE=\"%U\"></FORM>", FSWF("EXPLORE_change", "Change"));
  3111. #endif
  3112.  
  3113.     }
  3114.   /*  ============== End of the default/localized split =============== */
  3115.  
  3116.   u_fprintf(OUT, "</TD></TR>");
  3117.   u_fprintf(OUT, "</TABLE>");
  3118.   
  3119.  
  3120.   /* =============== All done ========================== */
  3121.   
  3122.   if(df)
  3123.     udat_close(df);
  3124.  
  3125.   if(df_default)
  3126.     udat_close(df_default);
  3127.  
  3128.   if(nf)
  3129.     unum_close(nf);
  3130.  
  3131.   u_fprintf(OUT, "<P><P>");
  3132.  
  3133.   showExploreCloseButton(locale, "DateTimePatterns");
  3134.  
  3135.   u_fprintf(OUT, "</TD><TD ALIGN=LEFT VALIGN=TOP>");
  3136.   printHelpTag("EXPLORE_DateTimePatterns", NULL);
  3137.   u_fprintf(OUT, "</TD>\r\n");
  3138.  
  3139.   showKeyAndEndItem("EXPLORE_DateTimePatterns", locale);
  3140.   
  3141.  
  3142.   /* ========= Show LPC's for reference ================= */
  3143.  
  3144.   /* ..... */
  3145.       /* locale pattern chars */
  3146.       {
  3147.     const UChar *charDescs[19];
  3148.  
  3149.     charDescs[0] = FSWF("localPatternChars0", "Era");
  3150.     charDescs[1] = FSWF("localPatternChars1", "Year");
  3151.     charDescs[2] = FSWF("localPatternChars2", "Month");
  3152.     charDescs[3] = FSWF("localPatternChars3", "Date");
  3153.     charDescs[4] = FSWF("localPatternChars4", "Hour Of Day 1");
  3154.     charDescs[5] = FSWF("localPatternChars5", "Hour Of Day 0"); 
  3155.     charDescs[6] = FSWF("localPatternChars6", "Minute");
  3156.     charDescs[7] = FSWF("localPatternChars7", "Second");
  3157.     charDescs[8] = FSWF("localPatternChars8", "Millisecond");
  3158.     charDescs[9] = FSWF("localPatternChars9", "Day Of Week");
  3159.     charDescs[10] = FSWF("localPatternChars10", "Day Of Year");
  3160.     charDescs[11] = FSWF("localPatternChars11", "Day Of Week In Month");
  3161.     charDescs[12] = FSWF("localPatternChars12", "Week Of Year");
  3162.     charDescs[13] = FSWF("localPatternChars13", "Week Of Month");
  3163.     charDescs[14] = FSWF("localPatternChars14", "Am/Pm");
  3164.     charDescs[15] = FSWF("localPatternChars15", "Hour 1");
  3165.     charDescs[16] = FSWF("localPatternChars16", "Hour 0");
  3166.     charDescs[17] = FSWF("localPatternChars17", "Timezone");
  3167.     charDescs[18] = 0;
  3168.     
  3169.     showStringWithDescription(myRB, locale, "SHOWlocalPatternChars", charDescs, "localPatternChars", FALSE);
  3170.       }
  3171. }
  3172.  
  3173. /*****************************************************************************
  3174.  *
  3175.  * Explorer for #'s
  3176.  */
  3177.  
  3178. void showExploreNumberPatterns(const char *locale, const char *b)
  3179. {
  3180.   UChar pattern[1024];
  3181.   UChar tempChars[1024];
  3182.   UNumberFormat  *nf = NULL; /* numfmt in the current locale */
  3183.   UNumberFormat  *nf_default = NULL; /* numfmt in the default locale */
  3184.   UErrorCode   status = U_ZERO_ERROR;
  3185.   int32_t i;
  3186.   double   value;
  3187.   char encodedPattern[1024];
  3188.   UChar valueString[1024];
  3189.   
  3190.   const UChar *defaultValueErr = 0,
  3191.               *localValueErr   = 0;
  3192.   
  3193.   const char *tmp, *tmpLimit;
  3194.   
  3195.   showKeyAndStartItem("EXPLORE_NumberPatterns", FSWF("EXPLORE_NumberPatterns", "Explore > Numbers"), locale, U_ZERO_ERROR);
  3196.  
  3197.   u_fprintf(OUT, "%U<P>", FSWF("formatExample_NumberPatterns_What","This example demonstrates formatting of numbers in this locale."));
  3198.  
  3199.   exploreFetchNextPattern(pattern, strstr(b,"EXPLORE_NumberPatterns")); 
  3200.  
  3201.   nf = unum_open(UNUM_DEFAULT,locale,  &status);
  3202.   
  3203.   if(U_FAILURE(status))
  3204.     {
  3205.       u_fprintf(OUT, "</TD></TR></TABLE></TD></TR></TABLE><P><HR>%U: ", FSWF("formatExample_errorOpen", "Couldn't open the formatter"));
  3206.       explainStatus(status, "EXPLORE_NumberPattern");
  3207.       return; /* ? */
  3208.     }
  3209.   
  3210.   unum_applyPattern(nf, TRUE, pattern, -1);
  3211.   
  3212.   unum_toPattern(nf, FALSE, tempChars, 1024, &status);
  3213.  
  3214.   if(U_FAILURE(status))
  3215.     {
  3216.       u_fprintf(OUT, "</TD></TR></TABLE></TD></TR></TABLE><P><HR>  %U<P>", FSWF("formatExample_errorToPattern", "Couldn't convert the pattern [toPattern]"));
  3217.       explainStatus(status, "EXPLORE_NumberPattern");
  3218.       return;
  3219.     }
  3220.  
  3221.   nf_default = unum_open(UNUM_DEFAULT, NULL, &status);
  3222.   
  3223.   if(U_FAILURE(status))
  3224.     {
  3225.       u_fprintf(OUT, "</TD></TR></TABLE></TD></TR></TABLE><P><HR>%U<P>", FSWF("formatExample_errorOpenDefault", "Couldn't open the default number fmt"));
  3226.       explainStatus(status, "EXPLORE_NumberPattern");
  3227.       return;
  3228.     }
  3229.   
  3230.   /* Load the default with a simplistic pattern .. */
  3231.   unum_applyPattern(nf_default, FALSE, FSWF("EXPLORE_NumberPatterns_defaultPattern", "#,###.###############"), -1);
  3232.       
  3233.   /* Allright. we've got 'nf' which is our custom pattern in the target 
  3234.      locale, and we've got 'nf_default' which is a pattern that we hope is
  3235.      reasonable for displaying a number in the *default* locale
  3236.  
  3237.      Confused yet?
  3238.   */
  3239.  
  3240.   value = 12345.6789; /* for now */
  3241.  
  3242.   /* Now, see if the user is trying to change the value. */
  3243.   if((tmp = strstr(b,"NP_LOC")))
  3244.     {
  3245.       /* Localized # */
  3246.       tmp += 7;
  3247.  
  3248.       unescapeAndDecodeQueryField(valueString, 1000, tmp);
  3249.       u_replaceChar(valueString, 0x0020, 0x00A0);
  3250.       
  3251.  
  3252.       status = U_ZERO_ERROR;
  3253.       value = unum_parseDouble(nf, valueString, -1, 0, &status);
  3254.       
  3255.       if(U_FAILURE(status))
  3256.     {
  3257.       status = U_ZERO_ERROR;
  3258.       localValueErr = FSWF("formatExample_errorParse_num", "Could not parse this, replaced with a default value.");
  3259.     }
  3260.     }
  3261.   else if ((tmp = strstr(b,"NP_DEF")) || (tmp = strstr(b,"NP_DBL")))
  3262.     {
  3263.       /* Localized # */
  3264.       tmp += 7;
  3265.  
  3266.       unescapeAndDecodeQueryField(valueString, 1000, tmp);
  3267.       u_replaceChar(valueString, 0x0020, 0x00A0);
  3268.  
  3269.  
  3270.       status = U_ZERO_ERROR;
  3271.       value = unum_parseDouble(nf_default, valueString, -1, 0, &status);
  3272.       
  3273.       if(U_FAILURE(status))
  3274.     {
  3275.       status = U_ZERO_ERROR;
  3276.       defaultValueErr = FSWF("formatExample_errorParse3", "Could not parse this, replaced with a default value.");
  3277.     }
  3278.     }
  3279.  
  3280.   /** TODO: replace with:
  3281.       
  3282.       case NP_LOC:
  3283.       value = unum_parseDouble(nf, str, ... )
  3284.       break;
  3285.       
  3286.       case NP_DEF:
  3287.       value = unum_parseDouble(defaultNF, str, ... );
  3288.          break;
  3289.   **/
  3290.  
  3291.   /* NOW we are ready ! */
  3292.  
  3293.   /* display the FORM, and fetch the current pattern */
  3294.   exploreShowPatternForm(pattern, locale, "NumberPatterns", strstr(b,"EXPLORE_NumberPatterns"), value, nf_default); 
  3295.  
  3296.  
  3297.   /* Now, display the results in <default> and in their locale */
  3298.   u_fprintf(OUT, "<TABLE BORDER=1><TR><TD>\r\n");
  3299.  
  3300.  
  3301.   /* ============ 'default' side of the table ==========  */
  3302.  
  3303.   unum_formatDouble(nf_default,value,tempChars, 1024, 0, &status);
  3304.  
  3305.   if(U_FAILURE(status))
  3306.     {
  3307.       u_fprintf(OUT, "%U<P>", FSWF("formatExample_errorFormatDefault", "Unable to format number using default version of the pattern"));
  3308.       explainStatus(status, "EXPLORE_NumberPattern");
  3309.     }
  3310.   else
  3311.     {
  3312.       u_fprintf(OUT, "<B><I>%U</I></B><BR>\r\n", defaultLanguageDisplayName());
  3313.       u_fprintf(OUT, "<FORM METHOD=GET ACTION=\"#EXPLORE_NumberPatterns\">\r\n");
  3314.       u_fprintf(OUT, "<INPUT NAME=_ TYPE=HIDDEN VALUE=%s>\r\n", locale);
  3315.       u_fprintf(OUT, "<INPUT TYPE=HIDDEN NAME=EXPLORE_NumberPatterns VALUE=\"");
  3316.       writeEscaped(pattern);
  3317.       u_fprintf(OUT, "\">\r\n");
  3318.  
  3319.       u_fprintf(OUT, "<TEXTAREA NAME=NP_DEF ROWS=1 COLS=20>");
  3320.       ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_BACKSLASH_ESCAPE, &status); 
  3321.       u_fprintf(OUT, "%U", tempChars); 
  3322.       
  3323.       /* should 'get/restore' here. */
  3324.       /*  ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &SubstituteWithValueHTML, &status); */
  3325.       ucnv_setFromUCallBack((UConverter*)u_fgetConverter(OUT), &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);
  3326.  
  3327.       status = U_ZERO_ERROR;
  3328.       
  3329.       u_fprintf(OUT, "</TEXTAREA><INPUT TYPE=SUBMIT VALUE=\"%U\"></FORM>", FSWF("EXPLORE_change", "Change"));
  3330.       
  3331.     }
  3332.   
  3333.   u_fprintf(OUT, "</TD><TD WIDTH=1 BGCOLOR=\"#EEEEEE\"><IMG SRC=/developerworks/opensource/icu/project/c.gif ALT=\"---\" WIDTH=0 HEIGHT=0></TD><TD>");
  3334.  
  3335.   /* ============ 'localized' side ================================= */
  3336.  
  3337.   unum_formatDouble(nf,value,tempChars, 1024, 0, &status);
  3338.  
  3339.   if(U_FAILURE(status))
  3340.     {
  3341.       u_fprintf(OUT, "%U<P>", FSWF("formatExample_errorFormat2", "Couldn't format the number normally"));
  3342.       explainStatus(status, "EXPLORE_NumberPattern");
  3343.     }
  3344.   else
  3345.     {
  3346.       /*  === local side */
  3347.       u_fprintf(OUT, "\r\n\r\n<!--  LOCALIZED SIDE -->\r\n<B>%U</B><BR>\r\n",curLocale?curLocale->ustr:FSWF("NoLocale","MISSING LOCALE NAME") );
  3348.       u_fprintf(OUT, "<FORM METHOD=GET ACTION=\"#EXPLORE_NumberPatterns\">\r\n");
  3349.       u_fprintf(OUT, "<INPUT NAME=_ TYPE=HIDDEN VALUE=%s>\r\n", locale);
  3350.       u_fprintf(OUT, "<INPUT TYPE=HIDDEN NAME=EXPLORE_NumberPatterns VALUE=\"");
  3351.       writeEscaped(pattern);
  3352.       u_fprintf(OUT, "\">\r\n");
  3353.       
  3354.       u_fprintf(OUT, "<TEXTAREA NAME=NP_LOC ROWS=1 COLS=20>");
  3355.       writeEscaped(tempChars);
  3356.       u_fprintf(OUT, "</TEXTAREA><INPUT TYPE=SUBMIT VALUE=\"%U\"></FORM>", FSWF("EXPLORE_change", "Change"));
  3357.  
  3358.       if(localValueErr)
  3359.     u_fprintf(OUT, "<P>%U", localValueErr);
  3360.     }
  3361.   /*  ============== End of the default/localized split =============== */
  3362.  
  3363.   u_fprintf(OUT, "</TD></TR>");
  3364.   u_fprintf(OUT, "</TABLE>");
  3365.  
  3366.   if(nf)
  3367.     unum_close(nf);
  3368.  
  3369.   if(nf_default)
  3370.     unum_close(nf_default);
  3371.   
  3372.   showExploreCloseButton(locale, "NumberPatterns");
  3373.   u_fprintf(OUT, "</TD><TD ALIGN=LEFT VALIGN=TOP>");
  3374.   printHelpTag("EXPLORE_NumberPatterns", NULL);
  3375.   u_fprintf(OUT, "</TD>\r\n");
  3376.  
  3377.   
  3378.   showKeyAndEndItem("EXPLORE_NumberPatterns", locale);
  3379. }
  3380.  
  3381.  
  3382. bool_t isSupportedLocale(const char *locale, bool_t includeChildren)
  3383. {
  3384.   UResourceBundle *newRB;
  3385.   UErrorCode       status = U_ZERO_ERROR;
  3386.   bool_t           supp   = TRUE;
  3387.  
  3388.   newRB = ures_open(myBundlePath(), locale, &status);
  3389.   if(U_FAILURE(status))
  3390.     supp = FALSE;
  3391.   else
  3392.     {
  3393.       if(status == U_USING_DEFAULT_ERROR)
  3394.     supp = FALSE;
  3395.       else if( (!includeChildren) && (status == U_USING_FALLBACK_ERROR))
  3396.     supp = FALSE;
  3397.       else
  3398.     {
  3399.       ures_get(newRB, "helpPrefix", &status);
  3400.  
  3401.       if(status == U_USING_DEFAULT_ERROR)
  3402.         supp = FALSE;
  3403.       else if( (!includeChildren) && (status == U_USING_FALLBACK_ERROR))
  3404.         supp = FALSE;
  3405.     }
  3406.  
  3407.       ures_close(newRB);
  3408.     }
  3409.  
  3410.   return supp;
  3411. }
  3412.  
  3413. #if 0
  3414. char standardFlags[] = "AAACAFAJALAMANAOAQARASATAUAVBABBBCBDBEBFBGBHBIBKBLBMBNBOBPBQBRBSBTBUBVBXBYCACBCDCECFCGCHCICJCKCMCNCOCQCRCSCTCUCVCWCYDJDODQDRECEGEIEKENERESETEUEZFAFGFIFJFMFOFPFQFRFSGAGBGGGHGIGJGKGLGMGOGPGQGRGTGVGYHAHKHMHOHQHRHUIDIMINIOIPIRISITIVIZJEJMJNJOJQJUKEKGKNKQKRKSKTKUKZLALELGLHLILOLQLSLTLULYMAMBMCMDMFMGMHMIMKMLMNMOMPMQMRMTMUMVMXMYMZNCNENFNGNHNINLNONPNRNSNTNUNZPAPCPEPKPLPMPOPPPSPUQARERMRORPRQRSRWSASBSCSESFSGSHSISLSMSNSOSPSTSUSVSWSXSYSZTCTDTETHTITKTLTNTOTPTSTUTVTWTXTZUGUKUPUSUVUYUZVCVEVIVMVQVTWAWFWQWSWZYMZAZIVNUATRSKPTLVJPILDZDK";
  3415.  
  3416. void showFlagImage(const char *locale, const char *extra)
  3417. {
  3418.   /* Show a little box with the currently viewed Locale */
  3419.     const  UChar  *flagImage;
  3420.     char flagPath[200];
  3421.     UResourceBundle *flagRB;
  3422.     UErrorCode status;
  3423.     char *ptr;
  3424.  
  3425.     status = U_ZERO_ERROR;
  3426.  
  3427.     flagPath[0] = 0;
  3428.  
  3429.     flagRB = ures_open(  myBundlePath(), locale, &status);
  3430.     if(U_SUCCESS(status) && (status != U_USING_DEFAULT_ERROR)) /* Important! don't want default flags.. */
  3431.       {
  3432.     flagImage = ures_get(flagRB, "flag", &status);
  3433.     
  3434.     if(U_SUCCESS(status) && (status != U_USING_DEFAULT_ERROR) && flagImage && *flagImage) /* if it's non null. Again, don't want default flags! */
  3435.       {
  3436.         u_austrcpy(flagPath, flagImage);
  3437.       }
  3438.       }
  3439.  
  3440.     /* As a fallback (actually a common case), we can use a flag of the form
  3441.        'za-t.gif' (from the CIA world factbook). 
  3442.        Extract the country and see if it matches our list of flags.. 
  3443.     */
  3444.     if(!flagPath[0] && (strlen(locale) >= 4) && (locale[2]!='f') ) /* try our fallback.. */
  3445.       {
  3446.     flagPath[0] = toupper(locale[3]);
  3447.     flagPath[1] = toupper(locale[4]);
  3448.     
  3449.     for(ptr=standardFlags;*ptr;ptr += 2)
  3450.       {
  3451.         if((flagPath[0] == ptr[0]) && (flagPath[1] == ptr[1]))
  3452.           break;
  3453.       }
  3454.     
  3455.     if(*ptr) /* convert it */
  3456.       {
  3457.         flagPath[0] = tolower(flagPath[0]);
  3458.         flagPath[1] = tolower(flagPath[1]);
  3459.         strcpy(flagPath+2,"-t.gif");
  3460.       }
  3461.     else
  3462.       flagPath[0] = 0;
  3463.       }
  3464.  
  3465.     
  3466.     /* OK, if we got anything.. */
  3467.    if(flagPath[0])
  3468.      {
  3469.        u_fprintf(OUT,"<IMG SRC=\"%s/localeexplorer/flags/%s\" BORDER=1 %s ALT=[flag]>",
  3470.          kStaticURLPrefix,
  3471.          flagPath,
  3472.          extra,
  3473.          locale);
  3474.      }
  3475.    ures_close(flagRB);
  3476.    
  3477.    if(strstr(locale, "EURO"))
  3478.      {
  3479.        u_fprintf(OUT, "<A HREF=\"http://europa.eu.int/euro\"><IMG SRC=\"%s/localeexplorer/flags/euro.gif\" BORDER=0 ALT=[euro] HEIGHT=25 WIDTH=32></A> ",
  3480.          kStaticURLPrefix); 
  3481.      }
  3482. }
  3483. #endif
  3484.  
  3485. #define kXKeyBGColor "\"#AAEEAA\" "
  3486.  
  3487. /* 
  3488.    pluggable UI
  3489. */
  3490. void showKeyAndStartItemShort(const char *key, const UChar *keyName, const char *locale, UErrorCode showStatus)
  3491. {
  3492.       u_fprintf(OUT, "<P><TABLE BORDER=0 CELLSPACING=0 WIDTH=100%%>");
  3493.       u_fprintf(OUT, "<TR><TD HEIGHT=5 BGCOLOR=\"#AFA8AF\" COLSPAN=2><IMG SRC=/developerworks/opensource/icu/project/c.gif ALT=\"---\" WIDTH=0 HEIGHT=0></TD></TR>\r\n");
  3494.       u_fprintf(OUT, "<TR><TD COLSPAN=1 WIDTH=0 VALIGN=TOP BGCOLOR=" kXKeyBGColor "><A NAME=%s><B>", key);
  3495.  
  3496.       if(keyName == NULL)
  3497.     keyName = FSWF( key, key );
  3498.  
  3499.       printHelpTag(key, keyName);
  3500.  
  3501.       u_fprintf(OUT,"</B></A>", keyName);
  3502.       u_fprintf(OUT," </TD><TD BGCOLOR=" kXKeyBGColor " WIDTH=0 ALIGN=RIGHT>");
  3503.       u_fprintf(OUT, " ");
  3504.       explainStatus(showStatus, key);
  3505. }
  3506.  
  3507. void showKeyAndStartItem(const char *key, const UChar *keyName, const char *locale, UErrorCode showStatus)
  3508. {
  3509.   showKeyAndStartItemShort(key,keyName,locale,showStatus);
  3510.   u_fprintf(OUT,"</TD><TR><TD COLSPAN=2>\r\n");
  3511. }
  3512.  
  3513. void showKeyAndEndItem(const char *key, const char *locale)
  3514. {
  3515.   u_fprintf(OUT, "</TR></TABLE>\r\n");
  3516. }
  3517.